renamed to getFinalBalance
Introduced function GetAssetDebt
This commit is contained in:
parent
22e77665ee
commit
215fb5e074
@ -77,13 +77,14 @@ public class Account {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
|
||||
public Double getMargin(AbstractAsset currency) {
|
||||
return this.getValue()
|
||||
return this.getFinalBalance()
|
||||
* this.leverage
|
||||
+ this.get(currency);
|
||||
|
||||
} ;
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
|
||||
synchronized void add(AssetPack pack) {
|
||||
@ -128,7 +129,36 @@ public class Account {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
public Double getValue( Exchange ex, AbstractAsset currency) {
|
||||
public Double getAssetDebt(Exchange ex, AbstractAsset currency) {
|
||||
Double result = 0.0;
|
||||
for (AbstractAsset a : assets.keySet()) {
|
||||
if (a.equals(currency)) {
|
||||
continue;
|
||||
}
|
||||
AssetPair pair = world.getAssetPair(a, currency);
|
||||
if (pair == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TradingEngine api = (TradingEngine) ex.getAPI(pair);
|
||||
Double v = get(a) * api.last_quote.price;
|
||||
|
||||
result = result + Math.abs(v);
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine final balance of this account, as if all assets would be sold
|
||||
* on exchange ex against given currency asset.
|
||||
*
|
||||
* @param ex Exchange to operate on
|
||||
* @param currency Currency against the assets should be sold.
|
||||
* @return final balance
|
||||
*
|
||||
*/
|
||||
public Double getFinalBalance(Exchange ex, AbstractAsset currency) {
|
||||
|
||||
Double result = get(currency);
|
||||
for (AbstractAsset a : assets.keySet()) {
|
||||
@ -148,11 +178,26 @@ public class Account {
|
||||
return result;
|
||||
}
|
||||
|
||||
public Double getValue(AbstractAsset currency){
|
||||
return getValue(world.getDefaultExchange(),currency);
|
||||
/**
|
||||
* Get the final balance as if all assets would be sold ob the default
|
||||
* exchange against given currency.
|
||||
* {@link #getFinalBalance(opensesim.world.Exchange, opensesim.world.AbstractAsset)}
|
||||
*
|
||||
* @param currency Currency for final balance
|
||||
* @return final balance
|
||||
*/
|
||||
public Double getFinalBalance(AbstractAsset currency) {
|
||||
return getFinalBalance(world.getDefaultExchange(), currency);
|
||||
}
|
||||
|
||||
public Double getValue(){
|
||||
return getValue(world.getDefaultAssetPair().getCurrency());
|
||||
/**
|
||||
* Determine final balance
|
||||
* {@link #getFinalBalance(opensesim.world.Exchange, opensesim.world.AbstractAsset) }
|
||||
*
|
||||
* @see DoublegetFinalBalance( Exchange ex, AbstractAsset currency)
|
||||
* @return Balance
|
||||
*/
|
||||
public Double getFinalBalance() {
|
||||
return getFinalBalance(world.getDefaultAssetPair().getCurrency());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user