Last active
September 30, 2019 03:12
-
-
Save larrybotha/b81011555f5e01f13fdc249255ebc7c0 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tradingStrategyMachine = Machine({ | |
id: 'three-step-trading-process', | |
initial: 'backtesting', | |
context: { | |
timesRefactored: 0, | |
}, | |
states: { | |
backtesting: { | |
on: { | |
CONSISTENT_GAINS: 'paperTrading', | |
CONSISTENT_LOSSES: [ | |
{ | |
cond: 'withinMaxRefactors', | |
target: 'refactoring', | |
}, | |
{ | |
target: 'abandoned', | |
} | |
], | |
} | |
}, | |
refactoring: { | |
exit: 'incrementRefactors', | |
on: { | |
REFACTORED: 'backtesting', | |
} | |
}, | |
paperTrading: { | |
entry: 'resetRefactorCount', | |
on: { | |
CONSISTENT_GAINS: 'cautiousTrading', | |
CONSISTENT_LOSSES: 'refactoring', | |
} | |
}, | |
cautiousTrading: { | |
on: { | |
CONSISTENT_GAINS: 'activeTrading', | |
CONSISTENT_LOSSES: 'paperTrading', | |
} | |
}, | |
activeTrading: { | |
type: 'final', | |
}, | |
abandoned: { | |
type: 'final', | |
}, | |
} | |
}, | |
{ | |
guards: { | |
withinMaxRefactors: ({timesRefactored}) => timesRefactored < 3, | |
}, | |
actions: { | |
incrementRefactors: assign(context => { | |
const {timesRefactored} = context; | |
return { | |
...context, | |
timesRefactored: timesRefactored + 1, | |
}; | |
}), | |
resetRefactorCount: assign(context => ({...context, timesRefactored: 0})) | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment