Crypto Portfolio Management
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © farzinsabbagh

//@version=5
indicator(title = "Crypto Portfolio Management", shorttitle = "CPM",
     overlay = true)

// ---- Inputs ----

tickerid_02 = input.symbol("BITSTAMP:ETHUSD",  "Second Asset")
tickerid_03 = input.symbol("POLONIEX:DASHUSDT","Third Asset")
tickerid_04 = input.symbol("BITSTAMP:XRPUSD",  "Forth Asset")
tickerid_05 = input.symbol("BITFINEX:LTCUSD",  "Fifth Asset")
tickerid_06 = input.symbol("BITFINEX:XMRUSD",  "Sixth Asset")
tickerid_07 = input.symbol("POLONIEX:DOGEUSD", "Seventh Asset")
tickerid_08 = input.symbol("KRAKEN:ADAUSD",    "Eighth Asset")
RiskFreeRate = input.float(title = "Risk Free Rate", defval = 2)
cell_height = input.int(title = "Cell Size height", defval = 6)
cell_width = input.int(title = "Cell Size Width", defval = 10)
// ---- Variables ----

var tbl = table.new(position = position.middle_center, columns = 8, rows = 9)
var buff = array.new_float(0)
var BTC_Yearly_Open = array.new_float(0)
var BTC_Yearly_Returns = array.new_float(0)
var BTC_Monthly_open = array.new_float(0)
var BTC_Monthly_return = array.new_float(0)
var ath_BTC = 0.0
var second_asset_yearly_open = array.new_float(0)
var second_asset_yearly_returns = array.new_float(0)
var second_asset_monthly_open = array.new_float(0)
var second_asset_monthly_returns = array.new_float(0)
var ath_second_asset = 0.0
var third_asset_yearly_open = array.new_float(0)
var third_asset_yearly_returns = array.new_float(0)
var third_asset_monthly_open = array.new_float(0)
var third_asset_monthly_returns = array.new_float(0)
var ath_third_asset = 0.0
var forth_asset_yearly_open = array.new_float(0)
var forth_asset_yearly_returns = array.new_float(0)
var forth_asset_monthly_open = array.new_float(0)
var forth_asset_monthly_returns = array.new_float(0)
var ath_forth_asset = 0.0
var fifth_asset_yearly_open = array.new_float(0)
var fifth_asset_yearly_returns = array.new_float(0)
var fifth_asset_monthly_open = array.new_float(0)
var fifth_asset_monthly_returns = array.new_float(0)
var ath_fifth_asset = 0.0
var sixth_asset_yearly_open = array.new_float(0)
var sixth_asset_yearly_returns = array.new_float(0)
var sixth_asset_monthly_open = array.new_float(0)
var sixth_asset_monthly_returns = array.new_float(0)
var ath_sixth_asset = 0.0
var seventh_asset_yearly_open = array.new_float(0)
var seventh_asset_yearly_returns = array.new_float(0)
var seventh_asset_monthly_open = array.new_float(0)
var seventh_asset_monthly_returns = array.new_float(0)
var ath_seventh_asset = 0.0
var eighth_asset_yearly_open = array.new_float(0)
var eighth_asset_yearly_returns = array.new_float(0)
var eighth_asset_monthly_open = array.new_float(0)
var eighth_asset_monthly_returns = array.new_float(0)
var ath_eighth_asset = 0.0
var buff2 = 0.0
var buff3 = 0.0
tbl_col = color.rgb(239,215,174,0)

// ---- Functions ----

get_each_year_open_price(_ser, _target_array) =>
    if((year-year[1]) != 0)
        array.push(_target_array,_ser)
        
get_each_month_open_price(_ser, _target_array) =>
    if((month-month[1]) !=0)
        array.push(_target_array,_ser)
        
make_sizes_equal(_array_1, _array_2) =>
    _array_1_size = array.size(_array_1)
    _array_2_size = array.size(_array_2)
    if(_array_1_size < _array_2_size)
        _num_ind_to_remove = _array_2_size - _array_1_size
        for i = 0 to (_num_ind_to_remove - 1)
            array.remove(_array_2, i)
    if(_array_2_size < _array_1_size)
        _num_ind_to_remove = _array_1_size - _array_2_size
        for i = 0 to (_num_ind_to_remove - 1)
            array.remove(_array_1, i)
        
calculate_return(_open, _target) =>
    for i = 1 to (array.size(_open)-1)
        array.push(_target, ((array.get(_open,i) - array.get(_open,i-1))/
         array.get(_open,i-1))*100)
        
// ---- Requests ----

[BTC_Daily, BTC_High] = request.security("BITSTAMP:BTCUSD", "D",
     [open, high])
[second_asset_daily, second_asset_high] = request.security(tickerid_02, "D",
     [open, high])
[third_asset_daily, third_asset_high] = request.security(tickerid_03, "D",
     [open, high])
[forth_asset_daily, forth_asset_high] = request.security(tickerid_04, "D",
     [open, high])
[fifth_asset_daily, fifth_asset_high] = request.security(tickerid_05, "D",
     [open, high])
[sixth_asset_daily, sixth_asset_high] = request.security(tickerid_06, "D",
     [open, high])
[seventh_asset_daily, seventh_asset_high] = request.security(tickerid_07, "D",
     [open, high])
[eighth_asset_daily, eighth_asset_high] = request.security(tickerid_08, "D",
     [open, high])
get_each_year_open_price(BTC_Daily, BTC_Yearly_Open)
get_each_month_open_price(BTC_Daily, BTC_Monthly_open)
get_each_year_open_price(second_asset_daily, second_asset_yearly_open)
get_each_month_open_price(second_asset_daily, second_asset_monthly_open)
get_each_year_open_price(third_asset_daily, third_asset_yearly_open)
get_each_month_open_price(third_asset_daily, third_asset_monthly_open)
get_each_year_open_price(forth_asset_daily, forth_asset_yearly_open)
get_each_month_open_price(forth_asset_daily, forth_asset_monthly_open)
get_each_year_open_price(fifth_asset_daily, fifth_asset_yearly_open)
get_each_month_open_price(fifth_asset_daily, fifth_asset_monthly_open)
get_each_year_open_price(sixth_asset_daily, sixth_asset_yearly_open)
get_each_month_open_price(sixth_asset_daily, sixth_asset_monthly_open)
get_each_year_open_price(seventh_asset_daily, seventh_asset_yearly_open)
get_each_month_open_price(seventh_asset_daily, seventh_asset_monthly_open)
get_each_year_open_price(eighth_asset_daily, eighth_asset_yearly_open)
get_each_month_open_price(eighth_asset_daily, eighth_asset_monthly_open)

// ---- Main Code ----
if (BTC_High > ath_BTC)
    ath_BTC := BTC_High
if (second_asset_high > ath_second_asset)
    ath_second_asset := second_asset_high
if (third_asset_high > ath_third_asset)
    ath_third_asset := third_asset_high
if (forth_asset_high > ath_forth_asset)
    ath_forth_asset := forth_asset_high
if (fifth_asset_high > ath_fifth_asset)
    ath_fifth_asset := fifth_asset_high
if (sixth_asset_high > ath_sixth_asset)
    ath_sixth_asset := sixth_asset_high
if (seventh_asset_high > ath_seventh_asset)
    ath_seventh_asset := seventh_asset_high
if (eighth_asset_high > ath_eighth_asset)
    ath_eighth_asset := eighth_asset_high

if (barstate.islast)
    
    // BTC yealy return calculation
    calculate_return(BTC_Yearly_Open,BTC_Yearly_Returns)
    // BTC monthly return calculation
    calculate_return(BTC_Monthly_open,BTC_Monthly_return)
    // Second asset yearly return
    calculate_return(second_asset_yearly_open,second_asset_yearly_returns)
    // Second asset monthly return
    calculate_return(second_asset_monthly_open,second_asset_monthly_returns)
    // Third asset yearly return
    calculate_return(third_asset_yearly_open,third_asset_yearly_returns)
    // Third asset monthly return
    calculate_return(third_asset_monthly_open,third_asset_monthly_returns)
    // Forth asset yearly return
    calculate_return(forth_asset_yearly_open,forth_asset_yearly_returns)
    // Forth asset monthly return
    calculate_return(forth_asset_monthly_open,forth_asset_monthly_returns)
    // Fifth asset yearly return
    calculate_return(fifth_asset_yearly_open,fifth_asset_yearly_returns)
    // Fifth asset monthly return
    calculate_return(fifth_asset_monthly_open,fifth_asset_monthly_returns)
    // Sixth asset yearly return
    calculate_return(sixth_asset_yearly_open,sixth_asset_yearly_returns)
    // Sixth asset monthly return
    calculate_return(sixth_asset_monthly_open,sixth_asset_monthly_returns)
    // Seventh asset yearly return
    calculate_return(seventh_asset_yearly_open,seventh_asset_yearly_returns)
    // Seventh asset monthly return
    calculate_return(seventh_asset_monthly_open,seventh_asset_monthly_returns)
    // eighth asset yearly return
    calculate_return(eighth_asset_yearly_open,eighth_asset_yearly_returns)
    // Eighth asset monthly return
    calculate_return(eighth_asset_monthly_open,eighth_asset_monthly_returns)
    
    table.set_border_color(tbl,color.black)
    table.set_border_width(tbl,2)
    
    // Col 0
    table.cell(tbl, 0, 0, "Pair", width = cell_width+5, height = cell_height ,
         bgcolor = color.orange)
    table.cell(tbl, 0, 1, "BITSTAMP:BTCUSD", bgcolor = color.white,
         width = cell_width+5, height = cell_height)
    table.cell(tbl, 0, 2, tickerid_02, bgcolor = tbl_col, width = cell_width+5,
         height = cell_height)
    table.cell(tbl, 0, 3, tickerid_03, bgcolor = color.white,
         width = cell_width+5, height = cell_height)
    table.cell(tbl, 0, 4, tickerid_04, bgcolor = tbl_col, width = cell_width+5,
         height = cell_height)
    table.cell(tbl, 0, 5, tickerid_05, bgcolor = color.white, width = cell_width+5,
         height = cell_height)
    table.cell(tbl, 0, 6, tickerid_06, bgcolor = tbl_col, width = cell_width+5,
         height = cell_height)
    table.cell(tbl, 0, 7, tickerid_07, bgcolor = color.white, width = cell_width+5,
         height = cell_height)
    table.cell(tbl, 0, 8, tickerid_08, bgcolor = tbl_col, width = cell_width+5,
         height = cell_height)

    // Col 1
    table.cell(tbl, 1, 0, "Y-Exp", width = cell_width, height = cell_height,
         bgcolor = color.orange)
    buff2 := math.round(array.avg(BTC_Yearly_Returns),2)
    table.cell(tbl, 1, 1, str.tostring(buff2)+"%",  bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.avg(second_asset_yearly_returns),2)
    table.cell(tbl, 1, 2, str.tostring(buff2)+"%",  bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.avg(third_asset_yearly_returns),2)
    table.cell(tbl, 1, 3, str.tostring(buff2)+"%",  bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.avg(forth_asset_yearly_returns),2)
    table.cell(tbl, 1, 4, str.tostring(buff2)+"%",  bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.avg(fifth_asset_yearly_returns),2)
    table.cell(tbl, 1, 5, str.tostring(buff2)+"%",  bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.avg(sixth_asset_yearly_returns),2)
    table.cell(tbl, 1, 6, str.tostring(buff2)+"%",  bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.avg(seventh_asset_yearly_returns),2)
    table.cell(tbl, 1, 7, str.tostring(buff2)+"%",  bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.avg(eighth_asset_yearly_returns),2)
    table.cell(tbl, 1, 8, str.tostring(buff2)+"%",  bgcolor = tbl_col,
         width = cell_width, height = cell_height)

    // Col 2
    table.cell(tbl, 2, 0, "Y-SDev", width = cell_width, height = cell_height,
         bgcolor = color.orange)
    buff2 := math.round(array.stdev(BTC_Yearly_Returns),2)
    table.cell(tbl, 2, 1, str.tostring(buff2)+"%", bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.stdev(second_asset_yearly_returns),2)
    table.cell(tbl, 2, 2, str.tostring(buff2)+"%", bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.stdev(third_asset_yearly_returns),2)
    table.cell(tbl, 2, 3, str.tostring(buff2)+"%", bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.stdev(forth_asset_yearly_returns),2)
    table.cell(tbl, 2, 4, str.tostring(buff2)+"%", bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.stdev(fifth_asset_yearly_returns),2)
    table.cell(tbl, 2, 5, str.tostring(buff2)+"%", bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.stdev(sixth_asset_yearly_returns),2)
    table.cell(tbl, 2, 6, str.tostring(buff2)+"%", bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.stdev(seventh_asset_yearly_returns),2)
    table.cell(tbl, 2, 7, str.tostring(buff2)+"%", bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.stdev(eighth_asset_yearly_returns),2)
    table.cell(tbl, 2, 8, str.tostring(buff2)+"%", bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    
    // Col 3
    table.cell(tbl, 3, 0, "M-Exp", width = cell_width, height = cell_height,
         bgcolor = color.orange)
    buff2 := math.round(array.avg(BTC_Monthly_return),2)
    table.cell(tbl, 3, 1, str.tostring(buff2)+"%", bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.avg(second_asset_monthly_returns),2)
    table.cell(tbl, 3, 2, str.tostring(buff2)+"%",bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.avg(third_asset_monthly_returns),2)
    table.cell(tbl, 3, 3, str.tostring(buff2)+"%",bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.avg(forth_asset_monthly_returns),2)
    table.cell(tbl, 3, 4, str.tostring(buff2)+"%",bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.avg(fifth_asset_monthly_returns),2)
    table.cell(tbl, 3, 5, str.tostring(buff2)+"%",bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.avg(sixth_asset_monthly_returns),2)
    table.cell(tbl, 3, 6, str.tostring(buff2)+"%",bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.avg(seventh_asset_monthly_returns),2)
    table.cell(tbl, 3, 7, str.tostring(buff2)+"%",bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.avg(eighth_asset_monthly_returns),2)
    table.cell(tbl, 3, 8, str.tostring(buff2)+"%",bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    
    // Col 4
    table.cell(tbl, 4, 0, "M-SDev", width = cell_width, height = cell_height,
         bgcolor = color.orange)
    buff2 := math.round(array.stdev(BTC_Monthly_return),2)
    table.cell(tbl, 4, 1, str.tostring(buff2)+"%", bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.stdev(second_asset_monthly_returns),2)
    table.cell(tbl, 4, 2, str.tostring(buff2)+"%",bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.stdev(third_asset_monthly_returns),2)
    table.cell(tbl, 4, 3, str.tostring(buff2)+"%",bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.stdev(forth_asset_monthly_returns),2)
    table.cell(tbl, 4, 4, str.tostring(buff2)+"%",bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.stdev(fifth_asset_monthly_returns),2)
    table.cell(tbl, 4, 5, str.tostring(buff2)+"%",bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.stdev(sixth_asset_monthly_returns),2)
    table.cell(tbl, 4, 6, str.tostring(buff2)+"%",bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.stdev(seventh_asset_monthly_returns),2)
    table.cell(tbl, 4, 7, str.tostring(buff2)+"%",bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round(array.stdev(eighth_asset_monthly_returns),2)
    table.cell(tbl, 4, 8, str.tostring(buff2)+"%",bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    
    // Col 5
    table.cell(tbl, 5, 0, "CorToBTC", width = cell_width, height = cell_height ,
         bgcolor = color.orange)
    table.cell(tbl, 5, 1, "1",bgcolor = color.white, width = cell_width,
         height = cell_height)
    buff := array.copy(BTC_Monthly_return)
    make_sizes_equal(buff,second_asset_monthly_returns)
    buff2 := math.round(array.covariance(buff,second_asset_monthly_returns) /
         (array.stdev(buff) * array.stdev(second_asset_monthly_returns)),2)
    table.cell(tbl, 5, 2, str.tostring(buff2), bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff := array.copy(BTC_Monthly_return)
    make_sizes_equal(buff,third_asset_monthly_returns)
    buff2 := math.round(array.covariance(buff,third_asset_monthly_returns) /
         (array.stdev(buff) * array.stdev(third_asset_monthly_returns)),2)
    table.cell(tbl, 5, 3, str.tostring(buff2), bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff := array.copy(BTC_Monthly_return)
    make_sizes_equal(buff,forth_asset_monthly_returns)
    buff2 := math.round(array.covariance(buff,forth_asset_monthly_returns) /
         (array.stdev(buff) * array.stdev(forth_asset_monthly_returns)),2)
    table.cell(tbl, 5, 4, str.tostring(buff2), bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff := array.copy(BTC_Monthly_return)
    make_sizes_equal(buff,fifth_asset_monthly_returns)
    buff2 := math.round(array.covariance(buff,fifth_asset_monthly_returns) /
         (array.stdev(buff) * array.stdev(fifth_asset_monthly_returns)),2)
    table.cell(tbl, 5, 5, str.tostring(buff2), bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff := array.copy(BTC_Monthly_return)
    make_sizes_equal(buff,sixth_asset_monthly_returns)
    buff2 := math.round(array.covariance(buff,sixth_asset_monthly_returns) /
         (array.stdev(buff) * array.stdev(sixth_asset_monthly_returns)),2)
    table.cell(tbl, 5, 6, str.tostring(buff2), bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff := array.copy(BTC_Monthly_return)
    make_sizes_equal(buff,seventh_asset_monthly_returns)
    buff2 := math.round(array.covariance(buff,seventh_asset_monthly_returns) /
         (array.stdev(buff) * array.stdev(seventh_asset_monthly_returns)),2)
    table.cell(tbl, 5, 7, str.tostring(buff2), bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff := array.copy(BTC_Monthly_return)
    make_sizes_equal(buff,eighth_asset_monthly_returns)
    buff2 := math.round(array.covariance(buff,eighth_asset_monthly_returns) /
         (array.stdev(buff) * array.stdev(eighth_asset_monthly_returns)),2)
    table.cell(tbl, 5, 8, str.tostring(buff2), bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    
    // Col 6
    table.cell(tbl, 6, 0, "SR Y/M", width = cell_width, height = cell_height,
         bgcolor = color.orange)
    buff2 := math.round((array.avg(BTC_Monthly_return) - RiskFreeRate)/
         array.stdev(BTC_Monthly_return),2)
    buff3 := math.round((array.avg(BTC_Yearly_Returns) - RiskFreeRate)/
         array.stdev(BTC_Yearly_Returns),2)
    table.cell(tbl, 6, 1, str.tostring(buff3)+"/"+str.tostring(buff2),
         bgcolor = color.white, width = cell_width, height = cell_height)
    buff2 := math.round((array.avg(second_asset_monthly_returns)-RiskFreeRate)/
         array.stdev(second_asset_monthly_returns),2)
    buff3 := math.round((array.avg(second_asset_yearly_returns) - RiskFreeRate)/
         array.stdev(second_asset_yearly_returns),2)
    table.cell(tbl, 6, 2, str.tostring(buff3)+"/"+str.tostring(buff2), bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff2 := math.round((array.avg(third_asset_monthly_returns)-RiskFreeRate)/
         array.stdev(third_asset_monthly_returns),2)
    buff3 := math.round((array.avg(third_asset_yearly_returns) - RiskFreeRate)/
         array.stdev(third_asset_yearly_returns),2)
    table.cell(tbl, 6, 3, str.tostring(buff3)+"/"+str.tostring(buff2), bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round((array.avg(forth_asset_monthly_returns)-RiskFreeRate)/
         array.stdev(forth_asset_monthly_returns),2)
    buff3 := math.round((array.avg(forth_asset_yearly_returns) - RiskFreeRate)/
         array.stdev(forth_asset_yearly_returns),2)
    table.cell(tbl, 6, 4, str.tostring(buff3)+"/"+str.tostring(buff2), bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff2 := math.round((array.avg(fifth_asset_monthly_returns)-RiskFreeRate)/
         array.stdev(fifth_asset_monthly_returns),2)
    buff3 := math.round((array.avg(fifth_asset_yearly_returns) - RiskFreeRate)/
         array.stdev(fifth_asset_yearly_returns),2)
    table.cell(tbl, 6, 5, str.tostring(buff3)+"/"+str.tostring(buff2), bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round((array.avg(sixth_asset_monthly_returns)-RiskFreeRate)/
         array.stdev(sixth_asset_monthly_returns),2)
    buff3 := math.round((array.avg(sixth_asset_yearly_returns) - RiskFreeRate)/
         array.stdev(sixth_asset_yearly_returns),2)
    table.cell(tbl, 6, 6, str.tostring(buff3)+"/"+str.tostring(buff2), bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    buff2 := math.round((array.avg(seventh_asset_monthly_returns)-RiskFreeRate)/
         array.stdev(seventh_asset_monthly_returns),2)
    buff3 := math.round((array.avg(seventh_asset_yearly_returns) - RiskFreeRate)/
         array.stdev(seventh_asset_yearly_returns),2)
    table.cell(tbl, 6, 7, str.tostring(buff3)+"/"+str.tostring(buff2), bgcolor = color.white,
         width = cell_width, height = cell_height)
    buff2 := math.round((array.avg(eighth_asset_monthly_returns)-RiskFreeRate)/
         array.stdev(eighth_asset_monthly_returns),2)
    buff3 := math.round((array.avg(eighth_asset_yearly_returns) - RiskFreeRate)/
         array.stdev(eighth_asset_yearly_returns),2)
    table.cell(tbl, 6, 8, str.tostring(buff3)+"/"+str.tostring(buff2), bgcolor = tbl_col,
         width = cell_width, height = cell_height)
    
    // Col 7
    table.cell(tbl, 7, 0, "DownFrom ATH %", width = cell_width,
         height = cell_height, bgcolor = color.orange)
    buff2 := math.round(((BTC_Daily-ath_BTC)/ath_BTC)*100,2)
    table.cell(tbl, 7, 1, str.tostring(buff2), bgcolor = color.white,
         width = cell_width, height = cell_height )
    buff2 := math.round(((second_asset_daily - ath_second_asset)/
         ath_second_asset)*100,2)
    table.cell(tbl, 7, 2, str.tostring(buff2), bgcolor = tbl_col,
         width = cell_width, height = cell_height )
    buff2 := math.round(((third_asset_daily - ath_third_asset)/
         ath_third_asset)*100,2)
    table.cell(tbl, 7, 3, str.tostring(buff2), bgcolor = color.white,
         width = cell_width, height = cell_height )
    buff2 :=math.round(((forth_asset_daily - ath_forth_asset)/
         ath_forth_asset)*100,2)
    table.cell(tbl, 7, 4, str.tostring(buff2), bgcolor = tbl_col,
         width = cell_width, height = cell_height )
    buff2 :=math.round(((fifth_asset_daily - ath_fifth_asset)/
         ath_fifth_asset)*100,2)
    table.cell(tbl, 7, 5, str.tostring(buff2), bgcolor = color.white,
         width = cell_width, height = cell_height )
    buff2 :=math.round(((sixth_asset_daily - ath_sixth_asset)/
         ath_sixth_asset)*100,2)
    table.cell(tbl, 7, 6, str.tostring(buff2), bgcolor = tbl_col,
         width = cell_width, height = cell_height )
    buff2 :=math.round(((seventh_asset_daily - ath_seventh_asset)/
         ath_seventh_asset)*100,2)
    table.cell(tbl, 7, 7, str.tostring(buff2), bgcolor = color.white,
         width = cell_width, height = cell_height )
    buff2 :=math.round(((eighth_asset_daily - ath_eighth_asset)/
         ath_eighth_asset)*100,2)
    table.cell(tbl, 7, 8, str.tostring(buff2), bgcolor = tbl_col,
         width = cell_width, height = cell_height )