For Programmers: Free Programming Magazines  


Home > Archive > Prolog > April 2004 > Is Prolog a good tool for this kind of problem?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Is Prolog a good tool for this kind of problem?
Neil

2004-04-13, 7:36 pm

We have an interesting potential project with a long-term client in
the financial services industry. While I know that we can code this
using a procedural approach, it tends to be pretty long and ugly.
Based on skimming through some of the Prolog tutorials and docs, it
appears as if Prolog might be a more efficient way to handle this type
of problem.

I'd appreciate any comments on this approach before we invest a lot of
time into it. Thanks in advance.


Scenario:
Determine the transactions required to rebalance a portfolio of mutual
funds so that the asset allocation matches a target allocation, while
minimizing the overall tax burden triggered by the transactions.

Details:
A portfolios consist of one or more individuals who each own one or
more accounts which each have one or more mutual funds.

Individuals have different tax rates.

Accounts may be of different types (e.g. taxable, non taxable). The
different account types also have restrictions with respect to the
amount of foreign content in the account. Buying and selling within a
non-taxable account does not trigger capital gains, while taxable
accounts are obviously subject to tax. If funds are sold at a loss
less than 30 days after they are purchased, it is not possible to
claim a loss on the sale. The gain (loss) on the sale of each mutual
fund will depend on the current value and the adjusted cost base
(similar to average cost of purchasing the funds).

Each mutual funds belongs one or more asset class (e.g. equity,
international equity, bonds, etc.). When more than one fund is in an
asset class, a prioritized list is used to determine which funds are
purchased to meet the target allocation.

It is not required to meet the exact asset allocation target, instead,
a target and a range is given (e.g. 20% +/- 3%).

The goal is to generate a list of transactions within each account
that will achieve the overall allocation while minimizing the overall
tax bill.
Bill Spight

2004-04-14, 11:41 am

Dear Neil,

> Scenario:
> Determine the transactions required to rebalance a portfolio of mutual
> funds so that the asset allocation matches a target allocation, while
> minimizing the overall tax burden triggered by the transactions.


This sounds like a linear programming problem. You might want to check
out

http://www-unix.mcs.anl.gov/otc/Gui...amming-faq.html

Best,

Bill
Benjamin Johnston

2004-04-15, 9:43 am


I don't mean to be intentionally difficult, but is it possible for you to
describe the problem without using any of the words: tax, asset, account,
buying, selling, capital gains, funds, purchased, claim, loss, mutual fund,
adjusted cost base, asset class, prioritized list, target allocation?

I suspect that the lack of useful responses relates to a poor understanding
of what is the mathematical/logical essence of the problem that you are
trying to describe. I have often dealt with "financial" people in the
past -- but find that they have a habit of describing the problem as they
see it, and not in a way that other people can see it. Particularly someone
like myself who understands each of the terms but am not familiar enough
with the underlying concepts to visualize the essense of the problem that
you describe. (I'm not perfect here either... I guess the same could be said
about myself, but I try...)

In other words, I just don't understand what you're saying. I suspect many
other people here are in the same boat. This is a Prolog discussion group,
not a taxation law group.

A better way of describing it for someone like myself would be as follows:

(This is just an example, it isn't an attempt at understanding what you have
written)

"We currently have a set of 'accounts' each with a class and a current
dollar value.
there is a function that can for each 'account' compute the cost of that
'account' from just the class and dollar value
the function is based on lookup tables on class and dollar value, and a
final multiplication by dollar value
We want to find a new allocation that minimizes the total cost; that is the
sum of the cost for each 'account' plus the total cost of creating the new
allocation.
The cost of moving dollar value from one 'account' to another 'account'
depends solely on the class of the originating 'account'. This is based on a
lookup table (e.g., classTax = 0.2, classNonTax = 0.3), and a final
multiplication by the value."

(Yes, okay, I used the word "account", but knowing what an account is, is
not essential to understanding the paragraph)

A problem like the one I just described probably isn't a great fit for
Prolog (too much mathematics involved). However it would be quite a good fit
for a constraint logic programming language (though too complex for just
linear programming). As to your specific problem, I'm not sure because I
don't understand it.

-Benjamin Johnston

"Neil" <njensen@habaneros.com> wrote in message
news:9ebd9631.0404131426.14c15f8e@posting.google.com...
> We have an interesting potential project with a long-term client in
> the financial services industry. While I know that we can code this
> using a procedural approach, it tends to be pretty long and ugly.
> Based on skimming through some of the Prolog tutorials and docs, it
> appears as if Prolog might be a more efficient way to handle this type
> of problem.
>
> I'd appreciate any comments on this approach before we invest a lot of
> time into it. Thanks in advance.
>
>
> Scenario:
> Determine the transactions required to rebalance a portfolio of mutual
> funds so that the asset allocation matches a target allocation, while
> minimizing the overall tax burden triggered by the transactions.
>
> Details:
> A portfolios consist of one or more individuals who each own one or
> more accounts which each have one or more mutual funds.
>
> Individuals have different tax rates.
>
> Accounts may be of different types (e.g. taxable, non taxable). The
> different account types also have restrictions with respect to the
> amount of foreign content in the account. Buying and selling within a
> non-taxable account does not trigger capital gains, while taxable
> accounts are obviously subject to tax. If funds are sold at a loss
> less than 30 days after they are purchased, it is not possible to
> claim a loss on the sale. The gain (loss) on the sale of each mutual
> fund will depend on the current value and the adjusted cost base
> (similar to average cost of purchasing the funds).
>
> Each mutual funds belongs one or more asset class (e.g. equity,
> international equity, bonds, etc.). When more than one fund is in an
> asset class, a prioritized list is used to determine which funds are
> purchased to meet the target allocation.
>
> It is not required to meet the exact asset allocation target, instead,
> a target and a range is given (e.g. 20% +/- 3%).
>
> The goal is to generate a list of transactions within each account
> that will achieve the overall allocation while minimizing the overall
> tax bill.



Nick Wedd

2004-04-15, 11:48 am

In message <9ebd9631.0404131426.14c15f8e@posting.google.com>, Neil
<njensen@habaneros.com> writes
>We have an interesting potential project with a long-term client in
>the financial services industry. While I know that we can code this
>using a procedural approach, it tends to be pretty long and ugly.
>Based on skimming through some of the Prolog tutorials and docs, it
>appears as if Prolog might be a more efficient way to handle this type
>of problem.
>
>I'd appreciate any comments on this approach before we invest a lot of
>time into it. Thanks in advance.
>
>
>Scenario:
>Determine the transactions required to rebalance a portfolio of mutual
>funds so that the asset allocation matches a target allocation, while
>minimizing the overall tax burden triggered by the transactions.
>
>Details:
>A portfolios consist of one or more individuals who each own one or
>more accounts which each have one or more mutual funds.
>
>Individuals have different tax rates.
>
>Accounts may be of different types (e.g. taxable, non taxable). The
>different account types also have restrictions with respect to the
>amount of foreign content in the account. Buying and selling within a
>non-taxable account does not trigger capital gains, while taxable
>accounts are obviously subject to tax. If funds are sold at a loss
>less than 30 days after they are purchased, it is not possible to
>claim a loss on the sale. The gain (loss) on the sale of each mutual
>fund will depend on the current value and the adjusted cost base
>(similar to average cost of purchasing the funds).
>
>Each mutual funds belongs one or more asset class (e.g. equity,
>international equity, bonds, etc.). When more than one fund is in an
>asset class, a prioritized list is used to determine which funds are
>purchased to meet the target allocation.
>
>It is not required to meet the exact asset allocation target, instead,
>a target and a range is given (e.g. 20% +/- 3%).
>
>The goal is to generate a list of transactions within each account
>that will achieve the overall allocation while minimizing the overall
>tax bill.


For what it's worth -

About fifteen years ago, I was paid to write a Prolog package to
calculate the minimum margin requirement of portfolios of options. The
investor could be long or short of stocks, and of puts and calls in
various stocks with various exercise prices and various exercise dates.
There was a required margin for each short position. There was also a
set of rules which allowed specified pairs of long and short positions
to be offset against one another, reducing the margin requirement. With
a complex portfolio, the pairings could be done in various ways with
different results. These rules (rather than the actual risk assessment
which the rules were trying, not entirely successfully, to measure) were
translated, rather neatly I felt, into Prolog.

Nick
--
Nick Wedd nick@maproom.co.uk
Neil Jensen

2004-04-15, 6:36 pm

"Benjamin Johnston" <superhero@benjaminjohnston.com.au> wrote in message
news:407e88c0$0$16593$5a62ac22@freenews.iinet.net.au...
>
> I don't mean to be intentionally difficult, but is it possible for you to
> describe the problem without using any of the words: tax, asset, account,
> buying, selling, capital gains, funds, purchased, claim, loss, mutual

fund,
> adjusted cost base, asset class, prioritized list, target allocation?
>


You're not being difficult at all, your point is well taken and I will try
and restate the problem in a way which makes more sense. The worst bit is
that I thought I had done that, which shows how far out of touch I am :-)

Here is a hopefully simplified description of what we're trying to
determine... hopefully it's adequate for an opinion on Prolog's suitability:

We current have a set of 'accounts' each with a class. Each 'account' holds
one or more 'mutual funds' and each 'mutual fund' has an asset class and a
current dollar value. There is a function that can compute the percentage of
dollars that belong to each asset class for all of the 'accounts' (this is
the current asset allocation).

We want to buy and/or sell 'mutual funds' within each 'account' so that we
meet a new target asset allocation. We want to meet the new target asset
allocation in a way that minimizes the costs associated with buying/selling
the 'mutual funds'.

The cost of buying/selling 'mutual funds' depends on the class of the
originating 'account'. This is based on a lookup table (e.g., classTax =
0.2, classNonTax = 0.3), and a final multiplication by the value.

Thanks in advance for any thoughts you may have.
Cheers,
Neil



Benjamin Johnston

2004-04-16, 10:31 pm



Ah thanks -- your problem is much more clearer now!

As you describe it, the rules involved do not appear to be overly complex --
the emphasis is in the optimization and not necessarily trying to find a
balance of all sorts of convoluted and complex rules. I find that Prolog is
great when it comes to problems involving complex symbols and rules, but not
necessarily so good for raw mathematics and optimization. Though constraint
logic programming (CLP) is supposed to address that limitation (I have very
little personal experience with CLP, though).

As your problem stands right now, it sounds very much like a linear
programming problem. All of your equations appear to be linear (i.e., of the
form z = 3 x + 2 y + ...) and a with a fixed number of classes that could be
enumerated into separate variables for the specification of the problem.

I would suggest two possible approaches (each can be done relatively cheaply
and quickly):

If there isn't all that much data (i.e., not too many accounts) you could
probably get away with defining the problem using Microsoft Excel and then
using the "Solver" functionality (if "Solver" doesn't appear under the Tools
menu, you may need to load the Add-In -- it comes free with Excel, just use
the help to find out how to install it). Provided the problem can be
expressed in a reasonably simple spreadsheet, Excel's Solver is really neat.

Failing that, get in contact with a researcher, PhD student, or even a late
year undergraduate studying Operations Research at your nearest university.
I wouldn't expect them to have too much difficulty formulating your problem
as an Operations Research problem -- and if they're actively working in the
field, they'll have access to (and be able to recommend) the tools that
might best solve your problem. This wouldn't be wasted time if in the end
they decided that your problem is too large or too complex for the tools
that they have -- the exercise will have at least developed a formal
mathematical formulation of the problem which can be used as a specification
for solving the problem, for selecting tools or for software development.


Also, the archives for the Operations Research newsgroup might be of
interest too:
sci.op-research
There's bound to be something there that would be of help.

-Benjamin Johnston

"Neil Jensen" <njensen@habaneros.com> wrote in message
news:baDfc.131397$Ig.126132@pd7tw2no...
> "Benjamin Johnston" <superhero@benjaminjohnston.com.au> wrote in message
> news:407e88c0$0$16593$5a62ac22@freenews.iinet.net.au...
to[color=darkred]
account,[color=darkred]
> fund,
>
> You're not being difficult at all, your point is well taken and I will try
> and restate the problem in a way which makes more sense. The worst bit is
> that I thought I had done that, which shows how far out of touch I am :-)
>
> Here is a hopefully simplified description of what we're trying to
> determine... hopefully it's adequate for an opinion on Prolog's

suitability:
>
> We current have a set of 'accounts' each with a class. Each 'account'

holds
> one or more 'mutual funds' and each 'mutual fund' has an asset class and a
> current dollar value. There is a function that can compute the percentage

of
> dollars that belong to each asset class for all of the 'accounts' (this is
> the current asset allocation).
>
> We want to buy and/or sell 'mutual funds' within each 'account' so that we
> meet a new target asset allocation. We want to meet the new target asset
> allocation in a way that minimizes the costs associated with

buying/selling
> the 'mutual funds'.
>
> The cost of buying/selling 'mutual funds' depends on the class of the
> originating 'account'. This is based on a lookup table (e.g., classTax =
> 0.2, classNonTax = 0.3), and a final multiplication by the value.
>
> Thanks in advance for any thoughts you may have.
> Cheers,
> Neil
>
>
>



Josh Smith

2004-04-20, 10:52 am

In article <9ebd9631.0404131426.14c15f8e@posting.google.com>, Neil wrote:
> We have an interesting potential project with a long-term client in
> the financial services industry. While I know that we can code this
> using a procedural approach, it tends to be pretty long and ugly.
> Based on skimming through some of the Prolog tutorials and docs, it
> appears as if Prolog might be a more efficient way to handle this type
> of problem.
>
> I'd appreciate any comments on this approach before we invest a lot of
> time into it. Thanks in advance.
>


While these types of optimization problems are perfect for attacking with
functional methods, I don't know that prolog is going to be more efficient
than something else.

the CLP suggestion is a good one, and Bratko's most current version
of his prolog book talks about it quite a bit. However, for something
like this I would recomend investigating a simulated annealing
approach since you just need a possible solution in a range. I've
been tinkering with an equity portfolio allocation calculator,
though I wasn't taking tax costs into account. I've found that the
SA route is less complicated than other methods and that a lot of
problems aren't solveable but are approximateable. Let's here it for
annecdotal evidence.

Hope this helps.

-jbs
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com