検証結果のfund.csvをグラフ化し検討する

1. まず基本のパッケージを読み込む

In [1]:
import pandas as pd
import time
import plotly
import plotly.graph_objs as go
plotly.offline.init_notebook_mode(connected=True)

raw = pd.read_csv(
    '/home/ubuntu/workspace/analysis/1711/[171126-4] Fund.tsv'
    ,delimiter   = '\t'
    ,index_col   = 'Date'
    ,parse_dates = True
)

layout = dict(
    autosize = False
    ,legend  = dict(
        xanchor  = "left"
        ,y = "1.05"
        ,orientation = "h"
    )
    ,margin = go.Margin(l=5 ,r=80 ,b=100 ,t=50)
    ,width  = 1200
    ,height = 500
    ,xaxis = dict(
         title = ""
        ,type  = "Date"
        ,showgrid  = True
        ,tickangle = 45
#         ,tickformat = "%Y-%m"
    )
    ,yaxis = dict(
        domain = [0 ,.95]
        ,title = ""
        ,side = "right"
#         ,exponentformat = "none"
#         ,separatethousands = False
#         ,tickprefix = ""
#         ,ticksuffix = "万円"
#         ,type = "log"
    )
    ,font = dict(
        family = 'Courier New, monospace'
        ,size  = 20
        ,color = '#7f7f7f'
    )
)

2. ループで一定期間ごとにグラフを出力

In [4]:
start = 1
end   = 17 #未満
span  = 17
cnt   = 0

for n in range(start ,end ,span):
    cnt = cnt+1
    
    s = str(2000+n) +"/1/1"
    e = str(2000+n+span) +"/12/31"

    raw_for = raw[s:e]

    print("2-1. 資産の推移(全期間)")
    data1 = [
         go.Scatter(x=raw_for.index ,y=raw_for.CashAsset ,name="決済済み現金資産"   ,line=dict(width=2))
        ,go.Scatter(x=raw_for.index ,y=raw_for.NetAssets ,name="未決済を含む純資産" ,line=dict(width=2) ,fill="tonexty")
        ,go.Scatter(x=raw_for.index ,y=raw_for.Maximum_YTD_NetAssets   ,name="年内の最高残高"     ,line=dict(width=2 ,shape="hvh" ,dash="dot"))
        ,go.Scatter(x=raw_for.index ,y=raw_for.Maximum_whole_NetAssets ,name="トータルの最高残高" ,line=dict(width=2 ,shape="hvh" ,dash="dash"))
    ]
    layout["title"] = "資産の推移(全期間)"
    plotly.offline.iplot(go.Figure(data=data1 ,layout=layout))

    time.sleep(1.5) #sleep(秒指定)


    print("2-1. 資産の推移(全期間、対数目盛)")
    layout["title"] = "資産の推移(全期間、対数目盛)"
    layout["yaxis"]["type"] = "log"
    plotly.offline.iplot(go.Figure(data=data1 ,layout=layout))

    layout["yaxis"]["type"] = "linear"
    time.sleep(1.5) #sleep(秒指定)


    print("2-2. 損益の推移(全期間・%)")
    data2 = [
         go.Scatter(x=raw_for.index ,y=raw_for.PL_whole_pct_CashAsset ,name="損益(現金資産・%)" ,line=dict(width=2))
        ,go.Scatter(x=raw_for.index ,y=raw_for.PL_whole_pct_NetAssets ,name="損益(純資産・%)"   ,line=dict(width=2) ,fill="tonexty")
    ]
    layout["title"] = "損益の推移(全期間・%)"
    plotly.offline.iplot(go.Figure(data=data2 ,layout=layout))

    # time.sleep(0.5) #sleep(秒指定)
    # print("2-2. 損益の推移(全期間・%、対数目盛)")
    # plotly.offline.iplot(go.Figure(data=data2 ,layout=layoutLog))

    time.sleep(1.5) #sleep(秒指定)


    print("2-3. 損益/年の推移(全期間・%)")
    data3 = [
        go.Scatter(x=raw_for.index ,y=raw_for.PL_YTD_pct_NetAssets ,name="損益/年(純資産・%)" ,fill="tonexty")
    ]
    layout["title"] = "損益/年の推移(全期間・%)"
    plotly.offline.iplot(go.Figure(data=data3 ,layout=layout))

    layout["title"] = ""
2-1. 資産の推移(全期間)
2-1. 資産の推移(全期間、対数目盛)