Skip to content

Commit

Permalink
fix(kernel): position price formula
Browse files Browse the repository at this point in the history
  • Loading branch information
zccz14 committed Feb 18, 2024
1 parent 60280fd commit 8280a8b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
10 changes: 10 additions & 0 deletions common/changes/@yuants/kernel/2024-02-18-08-15.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@yuants/kernel",
"comment": "fix position price formula",
"type": "patch"
}
],
"packageName": "@yuants/kernel"
}
8 changes: 5 additions & 3 deletions libraries/kernel/src/units/AccountInfoUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ export class AccountInfoUnit extends BasicUnit {
} else {
// 开仓的时候,如果有头寸,就要更新头寸
const nextVolume = roundToStep(thePosition.volume + order.volume, theProduct.volume_step ?? 1);
const nextPositionPrice =
(thePosition.position_price * thePosition.volume + order.traded_price! * order.volume) /
nextVolume;
const nextPositionPrice = theProduct.value_scale_unit
? nextVolume /
(thePosition.volume / thePosition.position_price + order.traded_volume! / order.volume)
: (thePosition.position_price * thePosition.volume + order.traded_price! * order.volume) /
nextVolume;
const position: IPosition = {
...thePosition,
volume: nextVolume,
Expand Down
8 changes: 5 additions & 3 deletions libraries/kernel/src/units/AccountSimulatorUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ export class AccountSimulatorUnit extends BasicUnit {
} else {
// 开仓的时候,如果有头寸,就要更新头寸
const nextVolume = roundToStep(thePosition.volume + order.volume, theProduct?.volume_step ?? 1);
const nextPositionPrice =
(thePosition.position_price * thePosition.volume + order.traded_price! * order.volume) /
nextVolume;
const nextPositionPrice = theProduct.value_scale_unit
? nextVolume /
(thePosition.volume / thePosition.position_price + order.volume / order.traded_price!)
: (thePosition.position_price * thePosition.volume + order.traded_price! * order.volume) /
nextVolume;
const position: IPosition = {
...thePosition,
volume: nextVolume,
Expand Down

0 comments on commit 8280a8b

Please sign in to comment.