Избранное трейдера DvF
Добрый день, друзья!
Писать много не буду. Напомню лишь о том, что если у Вас есть стойкое желание автоматизировать свою торговлю при этом сделать это с минимальными издержками без покупки дорогостоящего ПО, то решением может стать использование возможностей сайта Tradingview и моего парсера (см. детальную информацию о нем в постах:1, 2 и 3).
Возможности сайта Tradingview:
Settings = { Name = "GAZPROM_USD", tag = "GAZP", tag1 = "GAZP_USDRUB", line= { {Name = "line1", Color = RGB(0, 0, 255), Type = 1,Width = 1} } } vPrice=1; function Init() return 1 end function OnCalculate(index) local vOutFlag=0; local vGazp =(getCandlesByIndex(Settings.tag, 0, index-1, 1)[0].close or 1) ; local vUSDRUB=(getCandlesByIndex(Settings.tag1, 0, index-1, 1)[0].close or 1); if vGazp>0 then vOutFlag=1; else vOutFlag=0; end; if vUSDRUB>0 then vOutFlag=1; else vOutFlag=0; end; if vOutFlag > 0 then local Out = vGazp/vUSDRUB; vPrice=Out; end; return vPrice end3. В Квике создаем график с курсом доллара (USDRUB_TOM).
--переменные keyRateCB = 7.5 classCode = "TQOB" function CreateTable() t_id = AllocTable() AddColumn(t_id, 0, "Бумага", true, QTABLE_STRING_TYPE, 15) AddColumn(t_id, 1, "Цена", true, QTABLE_DOUBLE_TYPE, 15) AddColumn(t_id, 2, "Доходность, %", true, QTABLE_DOUBLE_TYPE, 15) AddColumn(t_id, 3, "Дюрация, лет", true, QTABLE_DOUBLE_TYPE, 15) AddColumn(t_id, 4, "Купон, %", true, QTABLE_DOUBLE_TYPE, 15) AddColumn(t_id, 5, "Премия к ЦБ, бп", true, QTABLE_INT_TYPE, 15) AddColumn(t_id, 6, "Погашение", true, QTABLE_STRING_TYPE, 15) t = CreateWindow(t_id) SetWindowCaption(t_id, "ОФЗ") end function string.split(str, sep) local fields = {} str:gsub(string.format("([^%s]+)", sep), function(f_c) fields[#fields + 1] = f_c end) return fields end function getParamNumber(code, param) return tonumber(getParamEx(classCode, code, param).param_value) end function formatData(prm) return string.format("%02d.%02d.%04d", prm%100, (prm%10000)/100, prm/10000) end CreateTable() arr = {} sec_list = getClassSecurities(classCode) sec_listTable = string.split(sec_list, ',') j = 0 for i = 1, #sec_listTable do secCode = sec_listTable[i] securityInfo = getSecurityInfo(classCode, secCode) short_name = securityInfo.short_name if short_name:find("ОФЗ 26") ~= nil then j = j + 1 r = {} r["short_name"] = short_name r["price"] = getParamNumber(securityInfo.code, "PREVPRICE") r["yield"] = getParamNumber(securityInfo.code, "YIELD") r["duration"] = getParamNumber(securityInfo.code, "DURATION")/365 couponvalue = getParamNumber(securityInfo.code, "COUPONVALUE") couponperiod = getParamNumber(securityInfo.code, "COUPONPERIOD") r["coupon"] = ((365/couponperiod) * couponvalue)/10 r["bonus"] = (r["yield"] - keyRateCB)*100 r["mat_date"] = getParamNumber(securityInfo.code, "MAT_DATE") table.insert(arr, j, r) end end table.sort(arr, function(a,b) return a["duration"] < b["duration"] end) for j = 1, #arr do row = InsertRow(t_id, -1) SetCell(t_id, row, 0, arr[j]["short_name"]) price = arr[j]["price"] SetCell(t_id, row, 1, string.format("%.2f", price), price) yield = arr[j]["yield"] SetCell(t_id, row, 2, string.format("%.2f", yield), yield) duration = arr[j]["duration"] SetCell(t_id, row, 3, string.format("%.2f", duration), duration) coupon = arr[j]["coupon"] SetCell(t_id, row, 4, string.format("%.2f", coupon), coupon) bonus = arr[j]["bonus"] SetCell(t_id, row, 5, string.format("%.0f", bonus), bonus) mat_date = arr[j]["mat_date"] SetCell(t_id, row, 6, formatData(mat_date), mat_date) end
Рисует линии вчерашних Hi, Low, Close, Open и сегодняшнего Open на графике
Очень удобно, наглядно показывает важные уровни вчерашнего дня.
#Thinkorswim studies #Рисует линии вчерашних Hi, Low, Close, Open и сегодняшнего Open на графике. #Thinkorswim https://radchenkovy.com/thinkorswim-live input sPeroid = {default DAY, WEEK, MONTH}; input iHigh = {default "yes", "no"}; input iLow = {default "yes", "no"}; input iClose = {default "yes", "no"}; input iOpen = {default "yes", "no"}; input iTodayOpen = {default "yes", "no"}; plot pHigh = if !iHigh then high(period = sPeroid)[1] else Double.NaN; plot pLow = if !iLow then low(period = sPeroid)[1] else Double.NaN; plot pClose = if !iClose then close(period = sPeroid)[1] else Double.NaN; plot pOpen = if !iOpen then open(period = sPeroid)[1] else Double.NaN; plot pTodayOpen = if !iTodayOpen then open(period = sPeroid)[0] else Double.NaN; pHigh.SetDefaultColor (Color.GREEN); pHigh.SetPaintingStrategy(PaintingStrategy.DASHES); pLow.SetDefaultColor(Color.RED); pLow.SetPaintingStrategy(PaintingStrategy.DASHES); pClose.SetDefaultColor (Color.GRAY); pClose.SetPaintingStrategy(PaintingStrategy.DASHES); pOpen.SetDefaultColor (Color.WHITE); pOpen.SetPaintingStrategy(PaintingStrategy.DASHES); pTodayOpen.SetDefaultColor (Color.WHITE); pTodayOpen.SetPaintingStrategy(PaintingStrategy.DASHES);;
Полная библиотека индикаторов, фильтров и сканеров для Thinkorswim в этом блоге bit.ly/2vKq4F8
В продолжение статьи о вреде избыточной диверсификации создадим полезный инструментарий️ по подбору акций. После этого сделаем простую ребалансировку⚖️ и добавим уникальные условия технических индикаторов, которых так часто не хватает в популярных сервисах. А затем сравним доходность отдельных активов и различных портфелей.
Во всем этом задействуем Pandas и минимизируем количество циклов. Погруппируем времянные ряды и порисуем графиков. Познакомимся с мультииндексами и их поведением. И всё это в Jupyter на Python 3.6.
Разбил много ☕кружек в поисках решения для ️быстрого получения длинных историй цен для большого количества активов в Python. Ещё имел смелость желать работать с ценами в numpy-массивах, а лучше сразу в pandas.
Стандартные подходы в лоб работали разочаровывающе, что приводило к выполнению запроса к БД в течение 30 секунд и более. Не желая мириться, я нашёл несколько решений, которые полностью меня удовлетворили.