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

Class to handle transations. More...

Inheritance diagram for smm.objects.Transaction:

Public Member Functions

def __init__
 Create a new Transaction instance.
def __str__
 Returns the content of this instance as string.
def getVolume
 Calculate the transaction volume.
def getHoldingPeriod
 Returns the holding period of shares.
def getSplitDetails
 Get details of a split transaction.
def getSwapDetails
 Get details of a swap transaction.
def setSplitDetails
 Set split transaction details.
def setSwapDetails
 Set swap transaction details.
def remove
 Delete 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 Transaction objects.
def getCount
 Returns the total number of Transaction.
def getInPeriod
 Returns all Transaction between start and end date.

Public Attributes

 value
 kind

Static Public Attributes

dictionary arguments
string psTopic = 'smm.transaction'
tuple id = Int(default=AutoReload, primary=True)
 Unique ID for each object.
tuple count = Decimal()
 Number of shares to buy or sell.
tuple value = Decimal()
 Value of one share.
tuple fee = Decimal()
 Overall transation fee.
tuple date = Date()
 Date of the transaction.
tuple exchange_id = Int()
 Property to store the ID of the referred Exchange object.
tuple exchange = Reference(exchange_id, Exchange.id)
 Reference to the Exchange object
tuple kind
 Type of transaction.
tuple position_id = Int()
 Property to store the ID of the referred Position object.
tuple position = Reference(position_id, 'Position.id')
 Reference to the Position object
tuple details = Unicode()
 Additional details for this transaction.
tuple NO_VALUE = decimal.Decimal('0.0000000000001')
 Very small value non-zero value to use for worthless expired positions.
- 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.

Private Member Functions

def _getDetails
 Get details of a transaction.
def _setDetails
 Set transaction details.

Static Private Attributes

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

Detailed Description

Class to handle transations.

Test:
tests.test_objects.TestObjects.test_Transaction_objects()

Constructor & Destructor Documentation

def smm.objects.Transaction.__init__ (   self,
  count,
  kind,
  position,
  date = datetime.date.today(),
  exchange = None,
  fee = None,
  value = None,
  details = None 
)

Create a new Transaction instance.

Parameters
selfThe object instance itself
countNumber of shares to trade (decimal.Decimal)
dateTransaction.date (datetime.date)
detailsTransaction.details
exchangeExchange to trade
feeTransaction.fee (decimal.Decimal)
kindTransaction.kind
valueValue of a single share (decimal.Decimal)
positionPosition object
Exceptions
ValueErrorRaised for missing arguments

References smm.objects.Transaction.position.

Member Function Documentation

def smm.objects.Transaction.__str__ (   self)

Returns the content of this instance as string.

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

Here is the caller graph for this function:

def smm.objects.Transaction._getDetails (   self,
  kind 
)
private

Get details of a transaction.

Parameters
selfThe object instance itself
kindtransaction kind
Returns
Tuple of peer transaction, ratio old count, ratio new count Values are None in case of errors
Exceptions
ValueErrorRaised for non-split transactions
See Also
setSplitDetails()

References smm.objects.Transaction.details, smm.objects.Share.kind, and smm.objects.Transaction.kind.

Referenced by smm.objects.Transaction.getSplitDetails(), and smm.objects.Transaction.getSwapDetails().

Here is the caller graph for this function:

def smm.objects.Transaction._setDetails (   self,
  kind,
  peer 
)
private

Set transaction details.

Parameters
selfThe object instance itself
kindtransaction kind
peerPeer transaction
Exceptions
ValueErrorRaised wrong transactions kind
Parameters
selfThe object instance itself
peerPeer transaction

References smm.objects.Transaction.count, smm.objects.Share.kind, smm.objects.Transaction.kind, and smm.objects.SMMBaseObject.update().

Referenced by smm.objects.Transaction.setSplitDetails(), and smm.objects.Transaction.setSwapDetails().

Here is the call graph for this function:

Here is the caller graph for this function:

def smm.objects.Transaction.get (   id = None)
static

Query Transaction objects.

Parameters
idReturns a single transaction specified by id.
Sorting:
The result is ordered ascending by date
Test:
tests.test_objects.TestObjects.test_Transaction_get()
def smm.objects.Transaction.getCount ( )
static

Returns the total number of Transaction.

def smm.objects.Transaction.getHoldingPeriod (   self,
  date = datetime.date.today() 
)

Returns the holding period of shares.

The function calculates the difference between a transaction date and given date.

Parameters
selfThe object instance itself
dateDate of the end of the holding period
Returns
The duration in days

References smm.objects.DailyQuote.date, and smm.objects.Transaction.date.

def smm.objects.Transaction.getInPeriod (   start,
  end,
  pos = None 
)
static

Returns all Transaction between start and end date.

Parameters
startStart date
endEnd date
posReturn transactions associated with this Position
def smm.objects.Transaction.getSplitDetails (   self)

Get details of a split transaction.

Returns
Tuple of peer transaction, ratio old count, ratio new count Values are None in case of errors
Exceptions
ValueErrorRaised for non-split transactions
See Also
setSplitDetails()
_getDetails()
Test:
tests.test_objects.TestObjects.test_Position_split()

References smm.objects.Transaction._getDetails().

Here is the call graph for this function:

def smm.objects.Transaction.getSwapDetails (   self)

Get details of a swap transaction.

Returns
Tuple of peer transaction, ratio old count, ratio new count Values are None in case of errors
Exceptions
ValueErrorRaised for non-swap transactions
See Also
setSwapDetails()
_getDetails()
Test:
tests.test_objects.TestObjects.test_Position_swap()

References smm.objects.Transaction._getDetails().

Here is the call graph for this function:

def smm.objects.Transaction.getVolume (   self,
  withFee = True 
)

Calculate the transaction volume.

Aquisitions increased the volume. Sales decreases it. Dividends are added to the volume. Splits and swaps don't have any effect.

Fees are processed for buy and sell transactions only.

Parameters
selfThe object instance itself
withFeeInclude the transaction fees in the volume
Returns
Volume of the transactions as decimal.Decimal value. Split transactions returns decimal.Decimal('0'). Worthless transactions returns decimal.Decimal('0').
Test:
tests.test_objects.TestObjects.test_Transaction_getVolume()

References smm.objects.Transaction.count, smm.objects.Transaction.fee, smm.objects.Share.kind, smm.objects.Transaction.kind, smm.objects.Transaction.NO_VALUE, and smm.objects.Transaction.value.

def smm.objects.Transaction.remove (   self)

Delete position.

The reference between share and watch list entry will be cleaned and Watch object will be removed from the database.

Emitted Notification:
smm.position.change, smm.transaction.remove
See Also
SMMBaseObject._remove()

References smm.objects.SMMBaseObject._remove(), and smm.objects.Transaction.position.

Here is the call graph for this function:

def smm.objects.Transaction.setSplitDetails (   self,
  peer 
)

Set split transaction details.

Parameters
selfThe object instance itself
peerPeer transaction
Exceptions
ValueErrorRaised for non-split transactions
See Also
getSplitDetails()
_setDetails()

References smm.objects.Transaction._setDetails().

Here is the call graph for this function:

def smm.objects.Transaction.setSwapDetails (   self,
  peer 
)

Set swap transaction details.

Parameters
selfThe object instance itself
peerPeer transaction
Exceptions
ValueErrorRaised for non-swap transactions
See Also
getSwapDetails()
_setDetails()

References smm.objects.Transaction._setDetails().

Here is the call graph for this function:

Member Data Documentation

string smm.objects.Transaction.__storm_table__ = "t_transaction"
staticprivate

Use given table to store all of this class inside.

dictionary smm.objects.Transaction.arguments
static
Initial value:
{
'count': 'decimal',
'value': 'decimal',
'fee': 'decimal',
'date': None,
'exchange': None,
'exchange_id': None,
'kind': 'unicode',
'position': None,
'position_id': None,
'details': 'unicode',
}
tuple smm.objects.Transaction.count = Decimal()
static

Number of shares to buy or sell.

Referenced by smm.objects.Transaction._setDetails(), and smm.objects.Transaction.getVolume().

tuple smm.objects.Transaction.date = Date()
static

Date of the transaction.

Referenced by smm.objects.Transaction.getHoldingPeriod().

tuple smm.objects.Transaction.details = Unicode()
static

Additional details for this transaction.

Currently supported events:

  • split outgoing (negative count)
    split:id peer transaction:ratio old:ratio new
  • split incoming (positive count)
    split:id peer transaction:ratio old:ratio new
  • swap outgoing (negative count)
    swap:id peer transaction:ratio old:ratio new
  • swap incoming (positive count)
    swap:id peer transaction:ratio old:ratio new
  • Worthless transactions (value == Transaction.NO_VALUE)
    worthless expired

Referenced by smm.objects.Transaction._getDetails().

tuple smm.objects.Transaction.exchange = Reference(exchange_id, Exchange.id)
static

Reference to the Exchange object

tuple smm.objects.Transaction.exchange_id = Int()
static

Property to store the ID of the referred Exchange object.

tuple smm.objects.Transaction.fee = Decimal()
static

Overall transation fee.

Referenced by smm.objects.Transaction.getVolume().

tuple smm.objects.Transaction.id = Int(default=AutoReload, primary=True)
static
tuple smm.objects.Transaction.kind
static
Initial value:
Enum(map={u'buy': 1, u'sell': 2, u'dividend': 3, u'split': 4,
u'swap': 5})

Type of transaction.

Adapt functions below after adding a new kind:

Referenced by smm.objects.Transaction._getDetails(), smm.objects.Transaction._setDetails(), and smm.objects.Transaction.getVolume().

smm.objects.Transaction.kind
tuple smm.objects.Transaction.NO_VALUE = decimal.Decimal('0.0000000000001')
static

Very small value non-zero value to use for worthless expired positions.

Referenced by smm.objects.Transaction.getVolume().

tuple smm.objects.Transaction.position = Reference(position_id, 'Position.id')
static
tuple smm.objects.Transaction.position_id = Int()
static

Property to store the ID of the referred Position object.

string smm.objects.Transaction.psTopic = 'smm.transaction'
static
tuple smm.objects.Transaction.value = Decimal()
static

Value of one share.

Referenced by smm.objects.Config.__str__(), and smm.objects.Transaction.getVolume().

smm.objects.Transaction.value

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