Skip to content

Commit

Permalink
HBS-3213: add etf fields
Browse files Browse the repository at this point in the history
  • Loading branch information
nshatvorov committed May 4, 2023
1 parent 622f64d commit fe6d9db
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
77 changes: 77 additions & 0 deletions links/etf.pine.link
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
makeNavTicker() => __financial_tickerid(syminfo.tickerid, "NAV", "D")
makeNavAllTicker() => __financial_tickerid(syminfo.tickerid, "NAV_ALL", "D")
makeAumTicker() => __financial_tickerid(syminfo.tickerid, "AUM", "D")
makeFundFlowsTicker() => __financial_tickerid(syminfo.tickerid, "FUND_FLOWS", "D")
getFundTF() => timeframe.isintraday ? "1D" : timeframe.period

nav = request.security(makeNavTicker(), getFundTF(), close, ignore_invalid_symbol=true, gaps=barmerge.gaps_on)
nav_all = request.security(makeNavAllTicker(), getFundTF(), close, ignore_invalid_symbol=true, gaps=barmerge.gaps_on)
aum = request.security(makeAumTicker(), getFundTF(), close, ignore_invalid_symbol=true, gaps=barmerge.gaps_on)
fund_flows = request.security(makeFundFlowsTicker(), getFundTF(), close, ignore_invalid_symbol=true, gaps=barmerge.gaps_on)

threeYears = 365 * 3
threeYears_ago = timenow - 1000 * 60 * 60 * 24 * threeYears
countOfBars3YearsAgo = fastSearchN(time, threeYears_ago, threeYears)

countETF(history, _bb, maxbarsback) =>
bb = _bb
if bar_index == 0
bb+=math.round(history[maxbarsback]*0)
(history - history[bb])/history[bb]

countSumOfInterval(history, _bb, maxbarsback) =>
bb = _bb
if bar_index == 0
bb+=math.round(history[maxbarsback]*0)
sum = 0.
for i = 0 to bb by 1
if not na(history[i])
sum += history[i]
sum

countYTD(history, lastYearOpen) =>
(history-lastYearOpen)/lastYearOpen

etfYTD(history) =>
var lastYearOpen = history
if year > year[1]
lastYearOpen := history
countYTD(history,lastYearOpen)

countFundFlowsYTD(history) =>
var sum = 0.
if not na(history)
sum += history
if year > year[1]
sum := history
sum

plot(countETF(nav, countOfBars1MonthAgo, month1), title="nav_perf.1M")
plot(countETF(nav, countOfBars3MonthAgo, month3), title="nav_perf.3M")
plot(countETF(nav, barsCountOneYear, oneYear), title="nav_perf.1Y")
plot(countETF(nav, countOfBars3YearsAgo, threeYears), title="nav_perf.3Y")
plot(countETF(nav, countOfBars5YearAgo, years5), title="nav_perf.5Y")
plot(etfYTD(nav), title="nav_perf.YTD")

plot(countETF(nav_all, countOfBars1MonthAgo, month1), title="nav_total_return.1M")
plot(countETF(nav_all, countOfBars3MonthAgo, month3), title="nav_total_return.3M")
plot(countETF(nav_all, barsCountOneYear, oneYear), title="nav_total_return.1Y")
plot(countETF(nav_all, countOfBars3YearsAgo, threeYears), title="nav_total_return.3Y")
plot(countETF(nav_all, countOfBars5YearAgo, years5), title="nav_total_return.5Y")
plot(etfYTD(nav_all), title="nav_total_return.YTD")

plot(countETF(aum, countOfBars1MonthAgo, month1), title="aum_perf.1M")
plot(countETF(aum, countOfBars3MonthAgo, month3), title="aum_perf.3M")
plot(countETF(aum, barsCountOneYear, oneYear), title="aum_perf.1Y")
plot(countETF(aum, countOfBars3YearsAgo, threeYears), title="aum_perf.3Y")
plot(countETF(aum, countOfBars5YearAgo, years5), title="aum_perf.5Y")
plot(etfYTD(aum), title="aum_perf.YTD")

plot(countSumOfInterval(fund_flows, countOfBars1MonthAgo, month1), title="fund_flows.1M")
plot(countSumOfInterval(fund_flows, countOfBars3MonthAgo, month3), title="fund_flows.3M")
plot(countSumOfInterval(fund_flows, barsCountOneYear, oneYear), title="fund_flows.1Y")
plot(countSumOfInterval(fund_flows, countOfBars3YearsAgo, threeYears), title="fund_flows.3Y")
plot(countSumOfInterval(fund_flows, countOfBars5YearAgo, years5), title="fund_flows.5Y")
plot(countFundFlowsYTD(fund_flows), title="fund_flows.YTD")

plot((close-nav)/nav, title="nav_discount_premium")
1 change: 1 addition & 0 deletions scanner.data.pine
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
#include <links/high_and_low.pine.link>
#include <links/perfomance.pine.link>
#include <links/business_day.pine.link>
#include <links/etf.pine.link>

0 comments on commit fe6d9db

Please sign in to comment.