How to structure Fixed Rate cashflows with monthly interest rate compounded and paid Quarterly - quantlib

I am using Quantlib swig implementatin in python. I am trying to model some loan agreements with fixed interest rate which is calculated monthly on simple basis and compounded quarterly basis.
Example
Issue Date March 18, 2011
First stub April 1, 2011
Second interest date july 1, 2011
Next interest payment dates every quarter after that October 1 and so on.
Coupon 8.45% calculated on simple basis and compounded every quarter.
I am unable to strcuture the flows using FixedRateLeg or FixedRateBond functions.
I notice that in C++ code there is an option to use FixedRateLeg with couponRates. I can provide Interest rate class with compounding of SimpleThenCompounded. But I think this function override is not available in Python swig version.
Any solutions as to how I can solve this ?

For the dates, genereting what you want it pretty easy since if nothing is defined, the stub will be at the beggining:
issueDate = ql.Date(18,3,2011)
maturityDate = ql.Date(1, 10, 2021)
schedule = ql.MakeSchedule(issueDate, maturityDate, ql.Period('3M'))
for date in [*schedule][:5]:
print(date.ISO())
2011-03-18
2011-04-01
2011-07-01
2011-10-01
2012-01-01
As for the rate, I'm not sure you mean by compounding quarterly if payments are quarterly. The ql.SimpleThenCompounded convention is used for example for TBills that might have more that one year, where the rate convention will be simple until one year and compounded for over a year.
Are you sure this won't give you what you want?
dayCount = ql.Actual360()
leg = ql.FixedRateLeg(schedule, dayCount, [100.], [0.0845])
for cf in leg:
print(cf.date().ISO(), cf.amount())

Related

power BI relative date filter

Relative Date Functionality in Power BI:
Issue #1:
Hi Team,
Need to know is there any way to implement the below relative date filter functionality in Power BI
Please note the following:
For year the base year should be current year, for now it should be 2021
For month the base month should be current month, for now it should be july and so on.
Issue#2:
Based on the above, we want to implement a functionality based on the below selection, where in if we select week, then we should see the count of a metric only for the weeks which are passed by the above filters and similarly for months, days etc. For eg, if we select year, then we should get the count for the year 2022 only as this is the only year passed by the above filter.
Thanks for any help!
Technically possible? I think so. Feasible? No, not really.
While there is some playroom with bookmarks, custom graphics and clever use of a wide range of measures and calculation groups - it would be an enormous task to get everything running correctly and smoothly.
Perhaps one option is to introduce this filtering functionality via a custom visual that takes your date column as input?

Different exchange rates in TaxTrans and LedgerTrans [AX 2009]

Hello I have a problem with Exchange rates in Dynamics AX 2009.
In TaxTrans table is different exchange rate than in LedgerTrans table.
In PurchParameters table Exchange Date Rate is set to DocumentDate but in TaxTrans is get exchange rate from TransDate.
What's wrong with that? Sounds like normal accounting behavior. You have provided an incomplete question with little to go on, so this answer could be wrong if you add more info.
Let's say your company operates in USD and today is June 10.
If you receive an invoice dated June 1 in CAD, your document date would be June 1, and your exchange rate would be the rate as of June 1. This depends on your accounting, but normally you want to know your cost on the date you accrued it...not the date you happened to transact it. This can give you more accurate costing.
Then when you pay a bill or whatever, the tax will be on the date of the transaction, so you will want the exchange rate on that transaction date.

Cumulative/Rolling Sum Blank Dates

I'm currently working on inventory reconciliation, and I've struggling to fill all days of the calendar with the cumulative sum of product we're currently storing:
Inventory level ($). = CALCULATE(SUM(ledger[cost]),FILTER(ALL(DimDate[Date]),DimDate[Date]<=MAX(ledger[Document Date])))
As you guys might notice it has at least 90% of all dates filled, however if we look closely to the graph, we can appreaciate March 5th of 2016 is missing just due to the fact there was no transaction during that day resulting on a blank value. However I'm trying to accomplish retrieving the previous day balance for those days with no transactions. e.g: for March 5th should have $17,038,462.32 (balance for the previous day March 4th).
I'm trying to work on another clause into the measure with functions such as EARLIER or LASTDATE, however I haven't been succesful.
Any insight or solutions works well thank you. Have a nice day.
You are using a wrong date field in your measure. Change it to the field from the Date table:
Inventory level. =
CALCULATE(
SUM(ledger[cost]),
FILTER(ALL(DimDate[Date]),DimDate[Date]<=MAX(DimDate[Date])))

Power BI: Calculating STDEVX.P over 6-Month period

I am attempting to calculate the most recent 6-Month STDEVX.P (not including the current month; so in May 2017, I'd like to the STDEVX.P for periods Nov 2016 - Apr 2017) for sales by product in order to further calculate variation in sales orders.
The Sales Data is made up of daily transactions so it contains transaction date: iContractsChargebacks[TransactionDate] and units sold: iContractsChargebacks[ChargebackUnits], but if there are no sales in a given period, then there will be no data for that month.
So, for example, on July 1st, sales for the past 6 months were the following:
Jan 100
Feb 125
Apr 140
May 125
Jun 130
March is missing because there were no sales. So, when I calculate STDEVX.P on the data set, it is calculating it over 5 periods, when in fact there were 6, just one happens to be zero.
At the end of the day, I need to calculate STDEVX.P for the current six month period. If when pulling the monthly sales numbers, it only comes back with 3 periods(months), then it needs to assume the other 3 periods with a zero value.
I thought about manually calculating standard deviation instead of using the DAX STDEVX.P formula and found these 2 links as a reference on how to do so, the first being closest to my need:
https://community.powerbi.com/t5/Desktop/Problem-with-STDEV/td-p/19731
Calculating the standard deviation from columns of values and frequencies in Power BI...
I attempted to make a go of it, but still am not getting the correct calculation. My code is:
STDEVX2 =
var Averageprice=[6M Sales]
var months=6
return
SQRT(
DIVIDE(SUMX(
FILTER(ALL(DimDate),
DimDate[Month ID]<=(MAX(DimDate[Month ID])-1) &&
DimDate[Month ID]>=(MAX(DimDate[Month ID])-6)
),
(iContractsChargebacks[SumOfOrderQuantity]-Averageprice)^2),
months
)
)
*note: Instead of using date parameters in the code, I created a calculated column in the date table that gives each Month a unique ID, makes it easier for me.
Your question would definitely be easier to answer with more explanation regarding your model. E.g. how you defined [SumOfOrderQuantity] and [6M Sales], since a mistake there could definitely impact the final result. Also, knowing what the result you're seeing is vs. the result you expect would be helpful (using sample data).
My guess, however, is that your DimDate table is a standard date table (with one row per date), but you want standard deviation by month.
The FILTER statement in your formula limits the date range to the prior 6 full months correctly, but it will still have one row per date. You can confirm this in Power BI by going into the Data View, selecting 'New Table' under Modeling on the ribbon, and putting your FILTER statement in:
Table = FILTER(ALL(DimDate),
DimDate[MonthID]<=(MAX(DimDate[MonthID])-1) &&
DimDate[MonthID]>=(MAX(DimDate[MonthID])-6))
Assuming you have more than one day of sales for a given month, calculating the variance by day rather than by month is going to mess things up.
What I'd suggest trying:
Table = FILTER(SUMMARIZE(ALL(DimDate),[MonthID]),
DimDate[MonthID]<=(MAX(DimDate[MonthID])-1) &&
DimDate[MonthID]>=(MAX(DimDate[MonthID])-6))
The additional SUMMARIZE statement means that you only get one row for each MonthID, rather than 1 row for each date. If your [6M Sales] is the monthly average across all 6 months, and [SumOfOrderQuantity] is the monthly sum for each month, then you should be set to go calculating the variance, squaring, dividing by 6, and square rooting.
If you need to do further troubleshooting, remember you can put a table on your canvas with MonthID, SumOfOrderQuantity and [6M Sales] and compare the numbers you expect at each stage of the calculation with the numbers you're seeing.
Hope this helps.
I was facing a similar problem while trying to calculate the coefficient of variation (Std. /Mean) by SKUS from sales data. I could use the Pivot-Unpivot function in Power Query editor to to do away with the problem of months with missing sales:
1) Export the data with any calculated columns
2) Reimport the data so that the calculated columns are also available in the power query editor
3) Pivoted the data by months
4) Replaced null values with 0s
5) Unpivoted the data
6) Close and apply the query
7) Add a calculated column for the coefficient of variation using the formula 
CV = CALCULATE(STDEV.P(Table1[Value]),ALLEXCEPT(Table1,Table1[Product]))/CALCULATE(AVERAGE(Table1[Value]),ALLEXCEPT(Table1,Table1[Product]))
Thus zero sales for the missing months will also be considered both for Standard Deviation and Mean.

Power BI Percentage of Month passed

I would like to create a calculated column or measure that shows the time elapsed in any given month. Preferably as a percentage.
I need to be able to compare productivity (rolling total) over a month's period between different months.So creating a percentage of time passed in a month would put every month on a level playing field.
Is there a way to do this?
Or is there a better way to compare productivity between 2 months on a rolling basis?
EDIT
I am graphing sales on a cumulative basis. Here is a picture of my graph to demonstrate.[][
Ideally I would like to be able to graph another person's sales on the same graph for a different month to compare.
The problem is each month is different and I don't think power bi allows much customization of the axes.
So I figured a potential solution would be to convert months to percentages of time passed, create two separate graphs and place them on top of each other to show the comparison of sales.
Using percentages doesn't sound right here: one person's "productivity" in February will appear lower than another person's productivity in March just because February has 3 less days.
Just use [Date].[Day].
To answer the original question (even though it shouldn't be used for this), month progress percentage calculated column:
MonthProgress% =
var DaysinMonth = DAY(
IF(
MONTH(MyTable[date]) = 12,
DATE(YEAR(MyTable[date]) + 1,1,1),
DATE(YEAR(MyTable[date]), MONTH(MyTable[date]) + 1, 1)
) - 1
)
return MyTable[date].[Day]/DaysinMonth*100
Also check DAX functions PARALLELPERIOD and DATEADD.
This is the solution I settled on.
I customized the ranges for the x and y axes so they match.
For the y-axis, I simply put the range from 0 to 50+ our highest month.
For the x-axis, I created a column with the DAY function so I got a number assigned to each day of the month which allowed me to manually set the chart range from 0 to 31. I have asked another question on how to only get workdays.