quantopian / pyfolio

Portfolio and risk analytics in Python
https://quantopian.github.io/pyfolio
Apache License 2.0
5.65k stars 1.77k forks source link

How to use with minute frequency data? #456

Open emin63 opened 6 years ago

emin63 commented 6 years ago

Hello. Is it possible to use pyfolio with minute frequency data?

When I try, I get the error

AttributeError: 'DataFrame' object has no attribute 'amount'

from pyfolio.utils.extract_rets_pos_txn_from_zipline.

gusgordon commented 6 years ago

Hi @emin63, there are some quirks of using pyfolio with minutely data — I would resample to daily before passing to pyfolio.

That error seems unrelated, though. What are the columns of your transactions DataFrame?

vonpupp commented 6 years ago

Hi, I am also interested in this due to 24/7 trading assets (i.e forex/cryptocurrencies).

Could you please point us into the right direction on how to do this resampling to make the data compatible with pyfolio @gusgordon? I think it is worth of consider including this feature in pyfolio IHMO.

I am new to zipline. Actually I am using enigma which is based in zipline and supports minute frequencies. If I am not mistaken zipline does not.

Thanks.

gusgordon commented 6 years ago

@vonpupp I agree that it could be a useful feature to have a conversion function.

For your purposes, pyfolio assumes returns and positions are end-of-day. So, for example, when we pass returns into pyfolio for US equities, those are basically the daily returns at 4:00 each day. You could cumulate your minutely returns each day by doing something like:

returns_daily = returns_minutely.add(1).groupby(pd.TimeGrouper('24H')).prod().add(-1)

For the positions, you would just grab the positions at a certain time each day, probably midnight. You can throw out the other minutes' data for positions.

Hope that helps!

868jjm commented 3 years ago

Hi, I am also interested in this due to 24/7 trading assets (i.e forex/cryptocurrencies).

Could you please point us into the right direction on how to do this resampling to make the data compatible with pyfolio @gusgordon? I think it is worth of consider including this feature in pyfolio IHMO.

I am new to zipline. Actually I am using enigma which is based in zipline and supports minute frequencies. If I am not mistaken zipline does not.

Thanks.

Did you get pyfolio to work with forex for crypo?