Share and Money Management  0.16
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Static Private Attributes | List of all members
smm.objects.Position Class Reference

Class to handle watch list entries. More...

Inheritance diagram for smm.objects.Position:

Public Member Functions

def __str__
 Returns the content of this instance as string.
def getShareCount
 Returns the numbers of shares in this position.
def getVolume
 Calculate the volume of a Position.
def getPerf
 Calculates the performance of a Position.
def getAvgBuy
 Calculates the average buy price.
def getLastQuote
 Returns the latest quotation of a share.
def Close
 Close position.
def Open
 Re-open position.
def removeTransaction
 Delete a transaction related to this position.
- Public Member Functions inherited from smm.objects.SMMBaseObject
def __init__
 Initialise the instance and set attributes optionally.
def __repr__
 Returns the representation of this object as string.
def update
 Update instance arguments.
def add2db
 Add an object to the database.

Static Public Member Functions

def get
 Query Position objects.
def getCount
 Returns the number of known Positions.
def getInPeriod
 Returns all Position with Transaction between start and end date.
def getTotalVolume
 Calculate the volume of all open positions.

Public Attributes

 open

Static Public Attributes

dictionary arguments
string psTopic = 'smm.position'
tuple id = Int(default=AutoReload, primary=True)
 Unique ID for each object.
tuple currency_id = Int()
 ID of the referred Currency object.
tuple currency = Reference(currency_id, Currency.id)
 Reference to the Currency object
tuple notes = Unicode()
 Additional notes to this position.
tuple open = Bool(default=True)
 Flag to mark open positions.
tuple share_id = Int()
 Property to store the ID of the referred Share object.
tuple share = Reference(share_id, Share.id)
 Reference to the Share object
tuple stop_id = Int()
 Property to store the ID of the referred Stop object.
tuple transactions
 Reference to all Transaction associated to this position
- Static Public Attributes inherited from smm.objects.SMMBaseObject
dictionary arguments
 Set of argument names for keyword arguments.
tuple encoding = sys.stdout.encodingorsys.getdefaultencoding()
 Encoding of all character strings.
 psTopic = None
 Publish Subscribe Topic for this class.

Static Private Attributes

string __storm_table__ = "t_position"
 Use given table to store all of this class inside.

High level transactions

Use this high level transactions for all trans with this position.

def buy
 Buy shares for the current Position.
def sell
 Sell parts of the current Position.
def worthless
 Whole position expired worthless.
def dividend
 Add a dividend Transaction.
def split
 Do a share split.
def swap
 Do a stock swap.

Detailed Description

Class to handle watch list entries.

Test:
tests.test_objects.TestObjects.test_Position_objects()

Member Function Documentation

def smm.objects.Position.__str__ (   self)

Returns the content of this instance as string.

References smm.objects.SMMBaseObject._encode(), smm.objects.Share.currency, smm.objects.DailyQuote.currency, smm.objects.Position.currency, smm.objects.Exchange.id, smm.objects.Currency.id, smm.objects.Share.id, smm.objects.DailyQuote.id, smm.objects.Transaction.id, smm.objects.Watch.id, smm.objects.Position.id, smm.objects.DailyQuote.open, smm.objects.Position.open, smm.objects.DailyQuote.share, smm.objects.Watch.share, and smm.objects.Position.share.

Referenced by smm.objects.SMMBaseObject.__repr__().

Here is the call graph for this function:

Here is the caller graph for this function:

def smm.objects.Position.buy (   self,
  count,
  value,
  fee = None,
  exchange = None,
  date = datetime.date.today() 
)

Buy shares for the current Position.

Parameters
selfThe object instance itself
countNumber of shares to trade (decimal.Decimal)
valueValue of a single share (decimal.Decimal)
feeTransaction.fee (decimal.Decimal)
exchangeExchange to trade
dateTransaction.date (datetime.date)
Returns
The created transaction object
Emitted Notification:
smm.position.change, smm.transaction.add

References smm.objects.Position.sell().

Referenced by smm.objects.Position.removeTransaction().

Here is the call graph for this function:

Here is the caller graph for this function:

def smm.objects.Position.Close (   self)

Close position.

Emitted Notification:
smm.position.change

Referenced by gui.MainWindow.OnFileExit(), smm.objects.Position.sell(), smm.objects.Position.swap(), and smm.objects.Position.worthless().

Here is the caller graph for this function:

def smm.objects.Position.dividend (   self,
  count,
  value,
  date = datetime.date.today() 
)

Add a dividend Transaction.

Parameters
selfThe object instance itself
countNumber of shares (decimal.Decimal)
valueValue per single share (decimal.Decimal)
dateTransaction.date (datetime.date)
Returns
The created transaction object
Emitted Notification:
smm.position.change, smm.transaction.add
def smm.objects.Position.get (   id = None,
  open = None,
  share = None,
  currency = None 
)
static

Query Position objects.

There are three ways for querying objects:

  • Querying by id returns a Position object or None
  • Querying entries using share
  • Querying without parameters to get all Position objects

Querying with share and open returns an Position object or None.

The last two ways returns always a storm.store.ResultSet.

Parameters
idReturns a Position specified by id.
openReturns all open / closed Positions
shareReturns all Positions matched with share.
currencyReturns all Positions matched with currency.
Sorting:
The result are unsorted
Test:
tests.test_objects.TestObjects.test_Position_get()
def smm.objects.Position.getAvgBuy (   self)

Calculates the average buy price.

The functions query all transactions of the current share position and calculates the weighted arithmetic mean of all "buy" transactions.

Parameters
selfThe object instance itself
Returns
Average buy as decimal.Decimal value

References smm.objects.Position.transactions.

def smm.objects.Position.getCount (   closed = False,
  open = False 
)
static

Returns the number of known Positions.

Parameters
openReturns the number of all open Position objects
closedReturns the number of all closed Position objects
def smm.objects.Position.getInPeriod (   start,
  end,
  open = False 
)
static

Returns all Position with Transaction between start and end date.

Parameters
startStart date
endEnd date
openLook for open Position only
Sorting:
The result are unsorted
def smm.objects.Position.getLastQuote (   self)

Returns the latest quotation of a share.

The function returns a tuple of two values:

  • the quotation (type decimal.Decimal)
  • the date (type datetime.Date)

All return values are None in case of error.

The function returns the latest daily quote if found. Otherwise is returns the data based on the last transaction. Or two times None, if nothing has been found.

Dividend transactions will be ignored.

Returns
A tuple of quotation and date
Test:
tests.test_objects.TestObjects.test_Position_getLastQuote()

References smm.objects.Share.currency, smm.objects.DailyQuote.currency, smm.objects.Position.currency, smm.objects.DailyQuote.share, smm.objects.Watch.share, and smm.objects.Position.share.

Referenced by smm.objects.Position.getPerf(), and smm.objects.Position.getVolume().

Here is the caller graph for this function:

def smm.objects.Position.getPerf (   self,
  withFee = False 
)

Calculates the performance of a Position.

Parameters
selfThe object instance itself
withFeeCalculate performance with or without
Returns
The absolute and relative performance in a tuple.
Two times decimal.Decimal("0") for no suitable transactions.
Test:
tests.test_objects.TestObjects.test_Position_getPerf()

References smm.objects.Position.getLastQuote(), smm.objects.Position.getShareCount(), and smm.objects.Position.transactions.

Here is the call graph for this function:

def smm.objects.Position.getShareCount (   self)

Returns the numbers of shares in this position.

Test:
tests.test_objects.TestObjects.test_Position_getPerf()

References smm.objects.Position.transactions.

Referenced by smm.objects.Position.getPerf(), smm.objects.Position.getVolume(), smm.objects.Position.sell(), smm.objects.Position.split(), smm.objects.Position.swap(), and smm.objects.Position.worthless().

Here is the caller graph for this function:

def smm.objects.Position.getTotalVolume (   currency)
static

Calculate the volume of all open positions.

Parameters
currencySpecifies the currency to summarise all open positions
Returns
Volume (decimal.Decimal)
See Also
getVolume()
def smm.objects.Position.getVolume (   self)

Calculate the volume of a Position.

Returns
Volume in decimal.Decimal
See Also
getTotalVolume()

References smm.objects.Position.getLastQuote(), and smm.objects.Position.getShareCount().

Here is the call graph for this function:

def smm.objects.Position.Open (   self)

Re-open position.

Emitted Notification:
smm.position.add

References smm.objects.DailyQuote.open, and smm.objects.Position.open.

Referenced by smm.objects.Position.removeTransaction().

Here is the caller graph for this function:

def smm.objects.Position.removeTransaction (   self,
  transaction,
  deleteRelated = True 
)

Delete a transaction related to this position.

The position will reopened after a transaction has been removed.

Parameters
selfThe object instance itself
transactionThe smm.objects.Transaction object
deleteRelatedDelete related transactions too
Exceptions
ValueErrorRaised if transaction not part of this position

References smm.objects.Position.buy(), smm.objects.Position.Open(), and smm.objects.Position.transactions.

Here is the call graph for this function:

def smm.objects.Position.sell (   self,
  count,
  value,
  fee = None,
  exchange = None,
  date = datetime.date.today(),
  autoclose = True 
)

Sell parts of the current Position.

Parameters
selfThe object instance itself
countNumber of shares to trade (decimal.Decimal)
valueValue of a single share (decimal.Decimal), use Transaction.NO_VALUE for worthless expired positions
feeTransaction.fee (decimal.Decimal)
exchangeExchange to trade
dateTransaction.date (datetime.date)
autocloseClose position if position is empty after this transaction
Returns
The created transaction object
Emitted Notification:
smm.position.change, smm.transaction.add

References smm.objects.Position.Close(), smm.objects.Position.getShareCount(), and smm.objects.Position.worthless().

Referenced by smm.objects.Position.buy().

Here is the call graph for this function:

Here is the caller graph for this function:

def smm.objects.Position.split (   self,
  oratio,
  nratio,
  date = datetime.date.today() 
)

Do a share split.

Splitting means that the position will decreased by the number of old shares and incresed by the number of new shares. The whole position will be splitted. The split will be realised within two transactions.

Parameters
selfThe object instance itself
oratioRatio old to new shares (decimal.Decimal)
nratioRatio old to new shares (decimal.Decimal)
dateSplit date (datetime.date)
Returns
Both split transactions (outgoing and incoming)
See Also
smm.Transaction.getSplitDetails()
smm.Transaction.setSplitDetails()
Emitted Notification:
smm.position.change, smm.transaction.add, smm.dailyquote.change

References smm.objects.Position.getShareCount(), smm.objects.DailyQuote.share, smm.objects.Watch.share, smm.objects.Position.share, and smm.objects.Position.swap().

Here is the call graph for this function:

def smm.objects.Position.swap (   self,
  oratio,
  nratio,
  ovalue,
  nvalue,
  nshare,
  date = datetime.date.today(),
  autoclose = True 
)

Do a stock swap.

The whole position will be swapped. If a open position exists for nshare, the new shares will be booked into.

Parameters
selfThe object instance itself
oratioRatio old to new shares (decimal.Decimal)
nratioRatio old to new shares (decimal.Decimal)
dateSplit date (datetime.date)
ovalueValue of a single old share (decimal.Decimal)
nvalueValue of a single new share (decimal.Decimal)
nshareShare to swap in
autocloseClose position if position is empty after this transaction
Returns
Both swap transactions (outgoing and incoming)
See Also
smm.Transaction.getSwapDetails()
smm.Transaction.setSwapDetails()
Test:
tests.test_objects.TestObjects.test_Position_swap()
Emitted Notification:
smm.transaction.add, smm.position.add, smm.position.change

References smm.objects.Position.Close(), smm.objects.Share.currency, smm.objects.DailyQuote.currency, smm.objects.Position.currency, and smm.objects.Position.getShareCount().

Referenced by smm.objects.Position.split().

Here is the call graph for this function:

Here is the caller graph for this function:

def smm.objects.Position.worthless (   self,
  fee = None,
  exchange = None,
  date = datetime.date.today(),
  autoclose = True 
)

Whole position expired worthless.

It's a sell with Transaction.NO_VALUE

Parameters
selfThe object instance itself
feeTransaction.fee (decimal.Decimal)
exchangeExchange to trade
dateTransaction.date (datetime.date)
autocloseClose position if position is empty after this transaction
Returns
The created transaction object
Test:
tests.test_objects.TestObjects.test_Position_worthless()
Emitted Notification:
smm.position.change, smm.transaction.add

References smm.objects.Position.Close(), and smm.objects.Position.getShareCount().

Referenced by smm.objects.Position.sell().

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

string smm.objects.Position.__storm_table__ = "t_position"
staticprivate

Use given table to store all of this class inside.

dictionary smm.objects.Position.arguments
static
Initial value:
{
'currency_id': None,
'currency': None,
'notes': 'unicode',
'open': None,
'share_id': None,
'share': None,
}
tuple smm.objects.Position.currency = Reference(currency_id, Currency.id)
static
tuple smm.objects.Position.currency_id = Int()
static

ID of the referred Currency object.

tuple smm.objects.Position.id = Int(default=AutoReload, primary=True)
static

Unique ID for each object.

Referenced by smm.objects.Position.__str__(), and smm.objects.SMMBaseObject._remove().

tuple smm.objects.Position.notes = Unicode()
static

Additional notes to this position.

tuple smm.objects.Position.open = Bool(default=True)
static

Flag to mark open positions.

Referenced by smm.objects.Position.__str__(), and smm.objects.Position.Open().

smm.objects.Position.open
string smm.objects.Position.psTopic = 'smm.position'
static
tuple smm.objects.Position.share = Reference(share_id, Share.id)
static
tuple smm.objects.Position.share_id = Int()
static

Property to store the ID of the referred Share object.

tuple smm.objects.Position.stop_id = Int()
static

Property to store the ID of the referred Stop object.

tuple smm.objects.Position.transactions
static
Initial value:
ReferenceSet(
id,
Transaction.position_id
)

Reference to all Transaction associated to this position

Referenced by smm.objects.Position.getAvgBuy(), smm.objects.Position.getPerf(), smm.objects.Position.getShareCount(), and smm.objects.Position.removeTransaction().


The documentation for this class was generated from the following file: