Skip to content

Commit 79355cc

Browse files
authored
Atualiza gráficos para usar plotly (#25)
* atualiza readme * atualiza gráfico para plotly * Revert "atualiza readme" This reverts commit e344a11.
1 parent a8af364 commit 79355cc

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

turingquant/benchmark.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pandas as pd
2-
import matplotlib.pyplot as plt
2+
import plotly.express as px
33
from datetime import datetime
4-
from matplotlib.ticker import PercentFormatter
54
from pandas_datareader import data
65

76

@@ -20,11 +19,16 @@ def benchmark(ticker, start: datetime, end: datetime, source='yahoo', plot=True)
2019
"""
2120

2221
asset = data.DataReader(ticker, data_source=source, start=start, end=end)
23-
returns_daily = asset['Close'].pct_change().fillna(0)
24-
cumulative = pd.DataFrame.cumprod(1 + returns_daily) - 1
22+
asset['Returns'] = asset['Close'].pct_change().fillna(0)
23+
asset['Cumulative Returns'] = pd.DataFrame.cumprod(1 + asset['Returns']) - 1
24+
2525
if plot:
26-
cumulative.plot()
27-
return cumulative
26+
fig = px.line(asset, x=asset.index, y='Cumulative Returns', title='Retorno cumulativo ' + ticker)
27+
fig.update_xaxes(title_text='Tempo')
28+
fig.update_yaxes(title_text='Retorno cumulativo')
29+
fig.show()
30+
31+
return asset['Cumulative Returns']
2832

2933

3034
def benchmark_ibov(start: datetime, end: datetime, source='yahoo', plot=True):

0 commit comments

Comments
 (0)