zvtvz / zvt

modular quant framework.
https://zvt.readthedocs.io/en/latest/
MIT License
3.09k stars 845 forks source link

Can GoldCrossFactor dump to local by pkl ? #154

Closed svjack closed 3 years ago

svjack commented 3 years ago

Can you try following code

        with open("day_gold_cross_factor.pkl", "wb") as f:
            pkl.dump(day_gold_cross_factor, f)

in init_selectors in MacdDayTrader ?

foolcage commented 3 years ago

the persistence of factor could be implemented in this way:

the reference is: https://github.com/zvtvz/zvt/blob/master/zvt/factors/zen/zen_factor.py

svjack commented 3 years ago

the persistence of factor could be implemented in this way:

  • define your factor domain, state(if need)
  • set Factor arg need_persist
  • implement sedes logic

the reference is: https://github.com/zvtvz/zvt/blob/master/zvt/factors/zen/zen_factor.py

Why can not support pickle ? it report error like following: PicklingError: Can't pickle ...: it's not the same object as... describe in https://stackoverflow.com/questions/1412787/picklingerror-cant-pickle-class-decimal-decimal-its-not-the-same-object Is this object construction have some complex import components ?

foolcage commented 3 years ago

@svjack yes. most of the pandas/numpy data type.

svjack commented 3 years ago

the persistence of factor could be implemented in this way:

  • define your factor domain, state(if need)
  • set Factor arg need_persist
  • implement sedes logic

the reference is: https://github.com/zvtvz/zvt/blob/master/zvt/factors/zen/zen_factor.py

Dose mainly persist and load logic of Factor cls is defined in persist_factor and load_factor in Factor class, And all i can do should with the help of them ?

foolcage commented 3 years ago

you're right. You could try MaFactor with need_persist ,it's simpler than ZenFacor which using State persistence too.

svjack commented 3 years ago

you're right. You could try MaFactor with need_persist ,it's more simpler than ZenFacor(with State persistence).

What should i do if i want to have a overview of all serialized factors in engine-map level ?

foolcage commented 3 years ago

you're right. You could try MaFactor with need_persist ,it's more simpler than ZenFacor(with State persistence).

What should i do if i want to have a overview of all serialized factors in engine-map level ?

not registering them to context yet,maybe latter.