Class CurrencyType
java.lang.Object
com.infinitekind.moneydance.model.MoneydanceSyncableItem
com.infinitekind.moneydance.model.CurrencyType
- All Implemented Interfaces:
com.infinitekind.tiksync.SyncableItem
public final class CurrencyType extends MoneydanceSyncableItem
A structure that represents a single type of currency, identified
by the three digit currency code. A stock or security in Moneydance
is represented as a currency as it is a unit of value that is relative
to some other value (ie the base currency)
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CurrencyType.Type
-
Field Summary
Fields Modifier and Type Field Description static int
CURRTYPE_CURRENCY
static int
CURRTYPE_SECURITY
static java.lang.String
SYNCABLE_TYPE_VALUE
static java.lang.String
TAG_RELATIVE_CURR_UUID
static java.lang.String
TAG_RELATIVE_TO_CURR
Fields inherited from class com.infinitekind.moneydance.model.MoneydanceSyncableItem
book, info, SECURITY_SUBTYPES_ITEM_TYPE
-
Constructor Summary
Constructors Constructor Description CurrencyType(CurrencyTable table)
Construct a CurrencyType object. -
Method Summary
Modifier and Type Method Description CurrencySnapshot
addSnapshotInt(int date, double userRate)
Deprecated.please use addSnapshotInt(date, userRate, relativeCurrency)CurrencySnapshot
addSnapshotInt(int date, double userRate, CurrencyType relativeCurrency)
Create a new snapshot with the given date and rate and return the result after adding it to the snapshot list.CurrencySplit
addStockSplit(long date, double splitRatio, int oldShares, int newShares)
Deprecated.use the addStockSplit method that takes an int date insteadCurrencySplit
addStockSplitInt(int date, double splitRatio, int oldShares, int newShares)
Add a stock split with the given ratio (which should match the old/new shares) on the given date (which decimal form is YYYYMMDD)double
adjustRateForSplitsInt(int date, double rate)
Given a value for this currency at the specified day, return the equivalent value in the currency today after adjusting for splits.double
adjustRateForSplitsInt(int date, double rate, int endDate)
Given a rate for this currency at the specified day, return the equivalent rate in the currency at endDate after adjusting for splits.long
adjustValueForSplits(long txnDate, long val)
Deprecated.use adjustValueForSplitsInt(int, long) insteadlong
adjustValueForSplitsInt(int txnDate, long val)
Given a number of currency units on the given day, return the equivalent number of units in todays currency value.long
adjustValueForSplitsInt(int txnDate, long val, int endDate)
Given a number of currency units on the given day, return the equivalent number of units in the endDate's currency value.int
compareToCurrency(CurrencyType curr)
Return an integer indicating whether this currency is less than, equal to, or greater than the given currency when sorting by type, name, and ID.long
convertValue(long baseCurrencyAmount)
Convert the givenbaseCurrencyAmount
value to it's value in this currency.static CurrencyType
currencyFromFields(int id, java.lang.String idString, java.lang.String name, double rate, int decimalPlaces, java.lang.String prefix, java.lang.String suffix, java.lang.String tickerSymbol, int effectiveDate, int currencyType, CurrencyTable table)
Construct a CurrencyType object.boolean
deleteItem()
Deletes this item and and all of the snapshots and splits that reference it.java.lang.String
format(long amt, char decimalChar)
Format the given value with the format NNNN.NNjava.lang.String
formatFancy(long amt, char decimalChar)
Format the given value with the format <prefix> N,NNN.NN <suffix>java.lang.String
formatFancy(long amt, char decimalChar, boolean includeDecimals)
Format the given value with the format <prefix> N,NNN.NN <suffix>java.lang.String
formatNoDecimals(long amt)
Format the given value with the format NNNNjava.lang.String
formatSemiFancy(long amt, char decimalChar)
Format the given value with the format N,NNN.NNdouble
getBaseRate()
Get the rate in terms of the base currency.CurrencyType.Type
getCurrencyType()
double
getDailyChange()
long
getDailyVolume()
int
getDecimalPlaces()
double
getDoubleValue(long longVal)
Get the 64 bit floating point representation of the given integer amount of this currencyint
getEffectiveDateInt()
Returns the int value (where the decimal form equals YYYYMMDD) representing the first date that this currency is active.boolean
getHideInUI()
Get a boolean flag indicating whether or not this currency should be displayed in user-friendly currency lists.int
getID()
java.lang.String
getIDForScheme(java.lang.String idScheme)
Returns the security/currency ID that was set for this CurrencyType using the given ID scheme.java.lang.String
getIDString()
long
getLongValue(double doubleVal)
java.lang.String
getName()
java.lang.String
getPrefix()
double
getRate(CurrencyType relativeToCurrency)
Get the rate of this currency relative to the given currency.double
getRate(CurrencyType relativeTo, int asOfDate)
Get the rate of this currency relative to the given currency as of the given date.double
getRateByDate(int dt, CurrencyType relativeCurrency)
Deprecated.double
getRawRate()
Deprecated.please use the non-raw rate methods and static functions in CurrencyUtildouble
getRawRateByDateInt(int dt)
Deprecated.CurrencyType
getRelativeCurrency()
Returns the currency to which this item's rates are relative.double
getRelativeRate()
Get the rate in terms of the relative currency.double
getRelativeRate(int asOfDate)
Get the rate in terms of the relative currency as of the given date.CurrencySnapshot
getSnapshotForDate(int date)
This finds the best historical price entry (aka snapshot) to use for the value of this currency or security on the given date.java.util.List<CurrencySnapshot>
getSnapshots()
java.util.List<CurrencySplit>
getSplits()
java.lang.String
getSuffix()
java.lang.String
getSyncItemType()
Subclasses should override this to return a static string identifying their type of objectCurrencyTable
getTable()
Returns the currency table that this currency is a part of.java.lang.String
getTickerSymbol()
double
getUserRate()
Deprecated.this has been deprecated in favor of getRate(CurrencyType relativeToCurrency) or getRelativeRate()double
getUserRateByDateInt(int dt)
Deprecated.long
invertValue(long currencyAmount)
Convert the givencurrencyAmount
value in this currency to a value in the base currency.boolean
isDirty()
void
itemWasUpdated()
This is called after an item is updated by calling itemWasUpdated(SyncRecord).void
itemWillSync()
This is called just before an item will be stored and/or synced when itemWillSync(SyncRecord) is called.long
parse(java.lang.String str, char decimalChar)
long
parse(java.lang.String str, char decimalChar, boolean quickDecimal)
Parse the given amount string given the provided decimal character.static long
parseRaw(java.lang.String str)
Parse a raw currency string, assuming there are enough decimal places.void
resetDirtyFlags()
void
setBaseRate(double newRate)
Set the rate in terms of the base currency.void
setCurrencyType(CurrencyType.Type newType)
void
setDailyChange(double change)
void
setDailyVolume(long vol)
void
setDecimalPlaces(int newDecimalPlaces)
void
setHideInUI(boolean hideInUI)
Set a boolean flag indicating whether or not this currency should be displayed in user-friendly currency lists.void
setIDForScheme(java.lang.String idScheme, java.lang.String newID)
Sets the security/currency ID for the given ID scheme.void
setIDString(java.lang.String newIDString)
void
setName(java.lang.String newName)
void
setPrefix(java.lang.String newPrefix)
void
setRate(double newRate, CurrencyType relativeCurr)
Set the new user (not raw) rate to the given value relative to the given currency.void
setRawRate(double newRawRate, boolean adjustRelativeSecurities)
Deprecated.please use setRelativeRate() or setRate() with non-decimal-adjusted rate valuesvoid
setRelativeCurrency(CurrencyType newRelativeCurrency)
Sets the currency to which this item's rates are relative.void
setRelativeRate(double newRate)
Set the rate in terms of the relative currency.CurrencySnapshot
setSnapshotInt(int date, double userRate)
If a snapshot exists for the specified date, set the rate and return it.CurrencySnapshot
setSnapshotInt(int date, double userRate, CurrencyType relativeCurr)
If a snapshot exists for the specified date, set the rate and return it.void
setSuffix(java.lang.String newSuffix)
void
setTickerSymbol(java.lang.String newTickerSymbol)
void
setUserRate(double newRate)
Deprecated.please use setRelativeRate() or setRate(double, CurrencyType) to set the ratevoid
setUserRate(double newRate, CurrencyType relativeCurr)
Deprecated.please use setRate(newRate, relativeCurrency)void
sortSnapshots()
void
sortStockSplits()
java.lang.String
toString()
long
unadjustValueForSplitsInt(int asofDate, long todayVal, int today)
Given a number of currency units as of today, return the equivalent number of units in the asofDate's currency value, which must be a previous date.Methods inherited from class com.infinitekind.moneydance.model.MoneydanceSyncableItem
addParameters, addTags, autoSyncsChanges, decodeKeywordList, doesParameterExist, duplicate, encodeKeywordList, equals, getAccountParameter, getAddress, getAddressParameter, getBook, getBooleanParameter, getCurrencyParameter, getCurrencyParameter, getCurrencyParameter, getDoubleParameter, getIntParameter, getKeywords, getLongParameter, getOriginalItem, getParameter, getParameter, getParameterCount, getParameterKeys, getPreference, getPreferenceBoolean, getPreferenceDouble, getPreferenceInt, getPreferenceIntArray, getPreferenceLong, getPreferenceStringList, getPreferenceSublist, getPreferenceSubset, getStringListParameter, getSyncInfo, getSyncTimestamp, getUUID, hasBeenSynced, hashCode, hasKeywordSubstring, initialize, isInEditingMode, isSyncable, itemWasUpdated, itemWillSync, makeSyncableItem, removeParameter, setAccountParameter, setAddress, setAddressParameter, setCurrencyParameter, setCurrencyParameter, setCurrencyParameter, setDirty, setEditingMode, setKeywords, setParameter, setParameter, setParameter, setParameter, setParameter, setParameter, setParameter, setParameterNoNotify, setPreference, setPreference, setPreference, syncItem
-
Field Details
-
SYNCABLE_TYPE_VALUE
public static final java.lang.String SYNCABLE_TYPE_VALUE- See Also:
- Constant Field Values
-
CURRTYPE_CURRENCY
public static final int CURRTYPE_CURRENCY- See Also:
- Constant Field Values
-
CURRTYPE_SECURITY
public static final int CURRTYPE_SECURITY- See Also:
- Constant Field Values
-
TAG_RELATIVE_TO_CURR
public static final java.lang.String TAG_RELATIVE_TO_CURR- See Also:
- Constant Field Values
-
TAG_RELATIVE_CURR_UUID
public static final java.lang.String TAG_RELATIVE_CURR_UUID- See Also:
- Constant Field Values
-
-
Constructor Details
-
CurrencyType
Construct a CurrencyType object.
-
-
Method Details
-
itemWasUpdated
public void itemWasUpdated()Description copied from class:MoneydanceSyncableItem
This is called after an item is updated by calling itemWasUpdated(SyncRecord). This can occur from the syncing process or from being loaded locally. Override this method to be notified.- Overrides:
itemWasUpdated
in classMoneydanceSyncableItem
-
itemWillSync
public void itemWillSync()Description copied from class:MoneydanceSyncableItem
This is called just before an item will be stored and/or synced when itemWillSync(SyncRecord) is called. Override this method to be notified or if you'd like to store anything into the info record to be synced.- Overrides:
itemWillSync
in classMoneydanceSyncableItem
-
getSyncItemType
public final java.lang.String getSyncItemType()Description copied from class:MoneydanceSyncableItem
Subclasses should override this to return a static string identifying their type of object- Specified by:
getSyncItemType
in interfacecom.infinitekind.tiksync.SyncableItem
- Overrides:
getSyncItemType
in classMoneydanceSyncableItem
-
getID
public int getID() -
deleteItem
public boolean deleteItem()Deletes this item and and all of the snapshots and splits that reference it. Use with caution!- Overrides:
deleteItem
in classMoneydanceSyncableItem
-
getEffectiveDateInt
public final int getEffectiveDateInt()Returns the int value (where the decimal form equals YYYYMMDD) representing the first date that this currency is active. This usually only pertains to securities. -
getCurrencyType
-
setCurrencyType
-
getIDString
public final java.lang.String getIDString() -
getName
public final java.lang.String getName() -
getPrefix
public final java.lang.String getPrefix() -
getSuffix
public final java.lang.String getSuffix() -
getDecimalPlaces
public final int getDecimalPlaces() -
getTickerSymbol
public final java.lang.String getTickerSymbol() -
setDecimalPlaces
public final void setDecimalPlaces(int newDecimalPlaces) -
getTable
Returns the currency table that this currency is a part of. Note: This is only available as of build 281. -
getDoubleValue
public final double getDoubleValue(long longVal)Get the 64 bit floating point representation of the given integer amount of this currency -
getLongValue
public final long getLongValue(double doubleVal) -
setIDString
public final void setIDString(java.lang.String newIDString) -
getRelativeCurrency
Returns the currency to which this item's rates are relative. Note: Only securities are permitted to have a relative currency that is not the base currency.- Since:
- Moneydance 2019 (build 1800)
-
setRelativeCurrency
Sets the currency to which this item's rates are relative. Note: Only securities are permitted to have a relative currency that is not equal to the base currency.- Since:
- Moneydance 2019.1 (build 1852)
-
setDailyVolume
public final void setDailyVolume(long vol) -
getDailyVolume
public final long getDailyVolume() -
setDailyChange
public final void setDailyChange(double change) -
getDailyChange
public final double getDailyChange() -
setTickerSymbol
public final void setTickerSymbol(java.lang.String newTickerSymbol) -
setName
public final void setName(java.lang.String newName) -
getRawRate
public final double getRawRate()Deprecated.please use the non-raw rate methods and static functions in CurrencyUtilGet the rate of this currency relative to the base currency in a value that can be multiplied or divided by the 'long' amount values to get a 'long' value in the other currency. -
setRawRate
public void setRawRate(double newRawRate, boolean adjustRelativeSecurities)Deprecated.please use setRelativeRate() or setRate() with non-decimal-adjusted rate valuesSet the rate relative to the base currency *already adjusted* for differences in decimal places between this currency and the base currency. -
setUserRate
public final void setUserRate(double newRate)Deprecated.please use setRelativeRate() or setRate(double, CurrencyType) to set the rateSet the price or rate for this currency using the normal decimal placement, not the decimal place adjusted values used when setting raw rates. Note: if there is a relative currency for this currency, then the given rate is assumed to be relative to that currency. -
setUserRate
Deprecated.please use setRate(newRate, relativeCurrency)Set the new user (not raw) rate to the given value relative to the given currency.- Since:
- Moneydance build 616
-
setRate
Set the new user (not raw) rate to the given value relative to the given currency. If relativeCurr is null then the given rate is considered to be relative to the base currency.- Since:
- Moneydance build 616
-
setRelativeRate
public final void setRelativeRate(double newRate)Set the rate in terms of the relative currency. If there is no relative currency then the rate is stored relative to the base currency of the file- Since:
- Moneydance 2019 (build 1800)
-
setBaseRate
public final void setBaseRate(double newRate)Set the rate in terms of the base currency.- Since:
- Moneydance 2019 (build 1800)
-
getRelativeRate
public final double getRelativeRate()Get the rate in terms of the relative currency. If there is no relative currency then this returns the rate in terms of the base currency.- Since:
- Moneydance 2019 (build 1800)
-
getRelativeRate
public final double getRelativeRate(int asOfDate)Get the rate in terms of the relative currency as of the given date. If there is no relative currency then this returns the rate in terms of the base currency.- Since:
- Moneydance 2019.1 (build 1851)
-
getBaseRate
public final double getBaseRate()Get the rate in terms of the base currency.- Since:
- Moneydance 2019 (build 1800)
-
getUserRate
public final double getUserRate()Deprecated.this has been deprecated in favor of getRate(CurrencyType relativeToCurrency) or getRelativeRate()Get the rate relative to the base currency -
getRate
Get the rate of this currency relative to the given currency. If relativeToCurrency is null then the rate is returned in terms of the base currency. -
getRate
Get the rate of this currency relative to the given currency as of the given date. If relativeToCurrency is null then the rate is returned in terms of the base currency. -
setPrefix
public final void setPrefix(java.lang.String newPrefix) -
setSuffix
public final void setSuffix(java.lang.String newSuffix) -
convertValue
public final long convertValue(long baseCurrencyAmount)Convert the givenbaseCurrencyAmount
value to it's value in this currency. -
invertValue
public final long invertValue(long currencyAmount)Convert the givencurrencyAmount
value in this currency to a value in the base currency. -
isDirty
public final boolean isDirty() -
resetDirtyFlags
public final void resetDirtyFlags() -
addStockSplit
public final CurrencySplit addStockSplit(long date, double splitRatio, int oldShares, int newShares)Deprecated.use the addStockSplit method that takes an int date insteadAdd a stock split. -
addStockSplitInt
public final CurrencySplit addStockSplitInt(int date, double splitRatio, int oldShares, int newShares)Add a stock split with the given ratio (which should match the old/new shares) on the given date (which decimal form is YYYYMMDD) -
adjustValueForSplits
public final long adjustValueForSplits(long txnDate, long val)Deprecated.use adjustValueForSplitsInt(int, long) insteadGiven a number of currency units on the given day, return the equivalent number of units in todays currency value. This is intended to be used mainly for stock splits. -
adjustValueForSplitsInt
public final long adjustValueForSplitsInt(int txnDate, long val)Given a number of currency units on the given day, return the equivalent number of units in todays currency value. This is intended to be used mainly for stock splits. -
adjustValueForSplitsInt
public final long adjustValueForSplitsInt(int txnDate, long val, int endDate)Given a number of currency units on the given day, return the equivalent number of units in the endDate's currency value. This is intended to be used mainly for stock splits. -
unadjustValueForSplitsInt
public final long unadjustValueForSplitsInt(int asofDate, long todayVal, int today)Given a number of currency units as of today, return the equivalent number of units in the asofDate's currency value, which must be a previous date. This is intended to be used mainly for stock splits.- Parameters:
asofDate
- The older date.todayVal
- The value as of thetoday
date.today
- Today's date (or at least a date more current thanasofDate
).- Returns:
- The value as of the given
asofDate
, un-adjusted for any splits.
-
adjustRateForSplitsInt
public final double adjustRateForSplitsInt(int date, double rate)Given a value for this currency at the specified day, return the equivalent value in the currency today after adjusting for splits. -
adjustRateForSplitsInt
public final double adjustRateForSplitsInt(int date, double rate, int endDate)Given a rate for this currency at the specified day, return the equivalent rate in the currency at endDate after adjusting for splits. -
getSplits
-
sortStockSplits
public final void sortStockSplits() -
sortSnapshots
public final void sortSnapshots() -
setSnapshotInt
If a snapshot exists for the specified date, set the rate and return it. Otherwise create a new snapshot on that date with the given rate and return the new snapshot. -
setSnapshotInt
If a snapshot exists for the specified date, set the rate and return it. Otherwise create a new snapshot on that date with the given rate and return the new snapshot. If relativeCurr is non-null then the price is first converted to the base price by getting the price of the given currency on the given date.- Since:
- Moneydance build 616
-
addSnapshotInt
Deprecated.please use addSnapshotInt(date, userRate, relativeCurrency)Create a new snapshot with the given date and (base currency) rate and return the result after adding it to the snapshot list. -
addSnapshotInt
public final CurrencySnapshot addSnapshotInt(int date, double userRate, CurrencyType relativeCurrency)Create a new snapshot with the given date and rate and return the result after adding it to the snapshot list. -
getSnapshots
-
getSnapshotForDate
This finds the best historical price entry (aka snapshot) to use for the value of this currency or security on the given date. The best entry should be the latest entry on or before the given date. If that doesn't exist, then the earliest entry after that date. If that doesn't exist then this returns null, in which case the caller should use the current rate or price rather than a snapshot.- Parameters:
date
-- Returns:
- the best historical prsice entry for the given date, if any
- Since:
- Moneydance 2017.7 build 1664
-
getRawRateByDateInt
@Deprecated public final double getRawRateByDateInt(int dt)Deprecated.Get the last known raw rate for this currency at the given time. Deprecated: please use getSnapshotForDate(date) and getRawRate() -
getRateByDate
Deprecated.Return the user rate as of the given date. Deprecated: please use getRate(date, relativeCurrency) -
getUserRateByDateInt
@Deprecated public final double getUserRateByDateInt(int dt)Deprecated.Return the user rate as of the given date. Deprecated: please use getSnapshotForDate(date) and getRate(relativeCurrency) -
setHideInUI
public final void setHideInUI(boolean hideInUI)Set a boolean flag indicating whether or not this currency should be displayed in user-friendly currency lists. Note: This is only available as of build 326 -
getHideInUI
public final boolean getHideInUI()Get a boolean flag indicating whether or not this currency should be displayed in user-friendly currency lists. Note: This is only available as of build 326 -
getIDForScheme
public java.lang.String getIDForScheme(java.lang.String idScheme)Returns the security/currency ID that was set for this CurrencyType using the given ID scheme. Returns null if no ID was set using the given scheme.- Since:
- Moneydance build 366
-
setIDForScheme
public void setIDForScheme(java.lang.String idScheme, java.lang.String newID)Sets the security/currency ID for the given ID scheme.- Since:
- Moneydance build 366
-
toString
public final java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
formatFancy
public final java.lang.String formatFancy(long amt, char decimalChar, boolean includeDecimals)Format the given value with the format <prefix> N,NNN.NN <suffix>- Since:
- Moneydance 2017
-
formatFancy
public final java.lang.String formatFancy(long amt, char decimalChar)Format the given value with the format <prefix> N,NNN.NN <suffix> -
formatSemiFancy
public final java.lang.String formatSemiFancy(long amt, char decimalChar)Format the given value with the format N,NNN.NN -
formatNoDecimals
public final java.lang.String formatNoDecimals(long amt)Format the given value with the format NNNN -
format
public final java.lang.String format(long amt, char decimalChar)Format the given value with the format NNNN.NN -
parse
public final long parse(java.lang.String str, char decimalChar) -
parse
public final long parse(java.lang.String str, char decimalChar, boolean quickDecimal)Parse the given amount string given the provided decimal character. If quickDecimal is true and getDecimalPlaces() is 2 then a decimal point will be inserted into the string so that "1234" will be parsed as if the user entered "12.34" -
parseRaw
public static final long parseRaw(java.lang.String str)Parse a raw currency string, assuming there are enough decimal places. This allows us to parse currency values into long integers without having a currency object because we assume that there are enough decimal places represented in the string. This lets us simply strip out decimal/comma characters are parse the raw integer result. -
compareToCurrency
Return an integer indicating whether this currency is less than, equal to, or greater than the given currency when sorting by type, name, and ID. This method was added in build 600 (Moneydance 2008) -
currencyFromFields
public static final CurrencyType currencyFromFields(int id, java.lang.String idString, java.lang.String name, double rate, int decimalPlaces, java.lang.String prefix, java.lang.String suffix, java.lang.String tickerSymbol, int effectiveDate, int currencyType, CurrencyTable table)Construct a CurrencyType object.
-