Empyrial icon indicating copy to clipboard operation
Empyrial copied to clipboard

str and Timestamp error

Open burakgulmez opened this issue 2 years ago • 1 comments

The code:

from empyrial import empyrial, Engine
portfolio = Engine(
                  start_date= "2021-01-01", #start date for the backtesting
                  end_date= "2022-05-01",
                  portfolio= tickers[:], #assets in your portfolio
                  weights = w2[:],
                  benchmark=["XU100.IS"]
)
print(empyrial(portfolio))
print(portfolio)

It gives an error like below.

TypeError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_10148/966461475.py in 11 ) 12 ---> 13 print(empyrial(portfolio)) 14 print(portfolio)

~\AppData\Roaming\Python\Python39\site-packages\empyrial.py in empyrial(my_portfolio, rf, sigma_value, confidence_value) 304 empyrial.SR = SR 305 --> 306 CR = qs.stats.calmar(returns) 307 CR = CR.tolist() 308 CR = str(round(CR, 2))

~\AppData\Roaming\Python\Python39\site-packages\quantstats\stats.py in calmar(returns, prepare_returns) 547 if prepare_returns: 548 returns = _utils._prepare_returns(returns) --> 549 cagr_ratio = cagr(returns) 550 max_dd = max_drawdown(returns) 551 return cagr_ratio / abs(max_dd)

~\AppData\Roaming\Python\Python39\site-packages\quantstats\stats.py in cagr(returns, rf, compounded) 500 total = _np.sum(total) 501 --> 502 years = (returns.index[-1] - returns.index[0]).days / 365. 503 504 res = abs(total + 1.0) ** (1.0 / years) - 1

TypeError: unsupported operand type(s) for -: 'str' and 'Timestamp'

burakgulmez avatar May 21 '22 06:05 burakgulmez

Hey!

Hmm... No idea how this happened, I cannot reproduce the error... I tried it with random stocks and weights and it worked. Check this out: https://colab.research.google.com/drive/1h2opIlfo34v6-jK5gd_PVQEm76Klroq9?usp=sharing

Keep me posted!

santoshlite avatar May 21 '22 12:05 santoshlite