What is wrong with this Switch statement? Im getting error cannot convert value text to type True/False - powerbi

Season =
SWITCH(TRUE(),
'sales'[Month] = "December" || "January" , "Winter",
'sales'[Month] = "February" || "March" , "Spring",
'sales'[Month] = "April" || "May" || "June" , "Summer",
'sales'[Month] = "July" || "August" || "September" , "Monsoon",
'sales'[Month] = "October" || "November", "Autumn",
"NA")
Cannot convert value 'January' of type Text to type True/False.

You need to repeat the column reference in each statement. e.g.
sales'[Month] = "December" || sales'[Month] = "January" , "Winter",

Related

If/Else Statement One Line

I'd like to incorporate if they currently have mmsa or jmmsa. MMMSA is balance over 2500 and JMMSA is balance over 100,000.
combined_2 = (
combined
.withColumn('mmsa_eligible',
F.when(
(F.col('min_bal_0_90_days') >= 2500) & (F.col('current_bal') >= 2500), 1
).otherwise(0)
)
.withColumn('jmmsa_eligible' ,
F.when(
(F.col('min_bal_0_90_days') >= 100000) & (F.col('current_bal') >= 100000), 1
).otherwise(0)
)
if jmmsa_eligible == 1 and jmmsa_current_flag == 0:
print ('Y')
else:
print ('N')

Need some help writing a strategy with different positions depending on three 3 signal variables

Hi I'm brand new in coding, and I am getting stuck every new line of code I try to write but hey its a learning process.
I'm doing a strategy based on the MACD variables.
-MACD_Line is either positive or negative.
-Signal_Line is either positive or negative.
-Histogram is either positive or negative.
Based on the historical prices there are 6 possibilities of combined signals either: ---, -++, --+, +--, ++- or +++.
What I want to do is pre-set different position sizes depending on these 6 possible output signals.
So for example: if "---" then short 50% of equity,
if "+++" then long 100% of equity,
if "-++" then short 25% of equity.
Therefore the equity position would change after one of the initial 3 variables changes.
My attempt:
strategy("HIST", overlay= false, initial_capital = 1, default_qty_type= strategy.percent_of_equity, default_qty_value= 100 )
//time inputs
startDate = input(title="Start Date", type=input.integer, defval=1, minval=1, maxval=31)
startMonth = input(title="Start Month", type=input.integer, defval=1, minval=1, maxval=12)
startYear = input(title="Start Year", type=input.integer, defval=2014, minval=1800, maxval=2100)
endDate = input(title="End Date", type=input.integer, defval=29, minval=1, maxval=31)
endMonth = input(title="End Month", type=input.integer, defval=3, minval=1, maxval=12)
endYear = input(title="End Year", type=input.integer, defval=2021, minval=1800, maxval=2100)
inDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and
(time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
//variable
ema26= ema(close,26)
ema12= ema(close,12 )
macdl= ema12-ema26
signal= ema(macdl, 9)
hist= macdl-signal
enterLong = crossover(macdl,0)
enterShort = crossunder(macdl,0)
s000 = if (hist <= 0 and macdl <= 0 and signal <=0)
s001 = if (hist > 0 and macdl <= 0 and signal <= 0)
s011 = if (hist > 0 and macdl > 0 and signal <= 0)
s111 = if (hist > 0 and macdl > 0 and signal > 0)
s011 = if (hist <= 0 and macdl > 0 signal > 0)
s001 = if (hist <= 0 and macdl <= 0 signal > 0)
if (inDateRange and s111)
strategy.entry(id="+", long=true)
if (inDateRange and s000)
strategy.entry(id="-", long=false)
if (not inDateRange)
strategy.close_all()
This should get you started in the right direction. You'll need to finish coding all the conditions yourself. See comments in code:
//#version=4
strategy("HIST", overlay= false, initial_capital = 1, default_qty_type= strategy.percent_of_equity, default_qty_value= 100 )
//time inputs
startDate = input(title="Start Date", type=input.integer, defval=1, minval=1, maxval=31)
startMonth = input(title="Start Month", type=input.integer, defval=1, minval=1, maxval=12)
startYear = input(title="Start Year", type=input.integer, defval=2014, minval=1800, maxval=2100)
endDate = input(title="End Date", type=input.integer, defval=29, minval=1, maxval=31)
endMonth = input(title="End Month", type=input.integer, defval=3, minval=1, maxval=12)
endYear = input(title="End Year", type=input.integer, defval=2021, minval=1800, maxval=2100)
inDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and
(time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
//variable
ema26= ema(close,26)
ema12= ema(close,12 )
macdl= ema12-ema26
signal= ema(macdl, 9)
hist= macdl-signal
enterLong = crossover(macdl,0)
enterShort = crossunder(macdl,0)
// Two last var names clashed with others, so used "X" in them.
s000 = hist <= 0 and macdl <= 0 and signal <= 0
s001 = hist > 0 and macdl <= 0 and signal <= 0
s011 = hist > 0 and macdl > 0 and signal <= 0
s111 = hist > 0 and macdl > 0 and signal > 0
s01X = hist <= 0 and macdl > 0 and signal > 0
s00X = hist <= 0 and macdl <= 0 and signal > 0
// Detect changes in conditions.
f_changeIn(_cond) => _cond and not _cond[1]
c000 = f_changeIn(s000)
c001 = f_changeIn(s001)
c011 = f_changeIn(s011)
c111 = f_changeIn(s111)
c01X = f_changeIn(s01X)
c00X = f_changeIn(s00X)
// Functions calculates position size from a % (0 - 1.0).
f_positionSize(_percentEquity) => strategy.equity * _percentEquity / close
// Generate orders on trasitions into conditions.
float positionSize = na
if inDateRange
if c000
positionSize := f_positionSize(0.5)
strategy.entry(id="+", long=false, qty = positionSize)
else if c011
positionSize := f_positionSize(1.0)
strategy.entry(id="+", long=false, qty = positionSize)
else if c111
positionSize := f_positionSize(1.0)
strategy.entry(id="+", long=true, qty = positionSize)
else
strategy.close_all()
// For debugging.
plot(positionSize, "Position size", color.orange, 2, plot.style_circles)

SAS Sql Case statement - how to convert SAS data step into sql case

I am trying to rewrite SAS data step into SAS Sql. I keep getting syntax errors for the versions I have written so far. The documentation and examples do not address the type of if/then I am working with.
Below is the original data step:
data tmp1;
set _tst1;
if put(tin, $gp.) = 'N' and
(missing(npi_num) or index(npi_num,"~") >= 1) then del1=1;
if put(tin, $gp.) = "Y" or
put(tin, $msp.) = "Y" or
put(cats(tin, npi_num), $pio.) =: "Y" or
put(cats(tin, npi_num), $cpc.) = 'Y' then del2=1;
if sum(num_elig, msr_yes, num_excl, msr_no) ^gt 0 then del3=1;
if sum(del1,del2,del3) > 0 then delete;
run;
Here is my attempt:
proc sql;
create table tst as
select *,
case
when
put(tin, $gp.) = 'N' and
(missing(npi_num) or index(npi_num,"~") >= 1)
then 1
else 0
end as del1
when
put(tin, $gp.) = "Y" or
put(tin, $msp.) = "Y" or
put(cats(tin, npi_num), $pio.) =: "Y" or
put(cats(tin, npi_num), $cpc.) = 'Y'
then 1
else 0
end as del2
when
sum(num_eligible, msr_met, num_exclusion, msr_not_met) ^gt 0
then 1
else 0
end as del3
from _tst1;
quit;

What's wrong with this logical operation work?

I'm trying to create an if statement that validates that the user's bet is either exactly 100, 300 or 500. What am i doing wrong?
if ((roundBet != 100) || (roundBet != 300) || (roundBet != 500))
{
cout << "Incorrect input";
// Call round again
newRound();
}
if ((roundBet != 100) || (roundBet != 300) || (roundBet != 500))
This will evaluates as true for all roundBet, because a number is either not 100(roundBet != 100 true) or 100 (which is not 300, roundBet != 300 true)
What you need is:
if ((roundBet != 100) && (roundBet != 300) && (roundBet != 500))
One of the alternatives will always be true, since if roundBet is, say, 100, then it will be different from 300 and 500.
Use a logical AND &&

C++ What If The Conditional Operator Were Left Associative [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This is a question I found that I don't really know the answer. Suppose we have the following code:
int grade = 100;
string finalgrade = (grade > 90) ? "High Pass"
: (grade > 75) ? "Pass"
: (grade >= 60) ? "low pass" : "fail";
How would the conditional operator be evaluated if it were left associative?
If ?: were left-associative, that would mean that:
a ? b : c ? d : e
would be equivalent to:
(a ? b : c) ? d : e
instead of:
a ? b : (c ? d : e)
Applying this to your example, you'd get:
string finalgrade = ( ( (grade > 90)
? "High Pass"
: (grade > 75))
? "Pass"
: (grade >= 60))
? "low pass"
: "fail";
which---assuming that the compiler didn't complain about the mismatched types---for grade = 100 would result in:
string finalgrade = ( ( true
? "High Pass"
: (grade > 75))
? "Pass"
: (grade >= 60))
? "low pass"
: "fail";
string finalgrade = ( "High Pass"
? "Pass"
: (grade >= 60))
? "low pass"
: "fail";
string finalgrade = "Pass"
? "low pass"
: "fail";
string finalgrade = "low pass";
in your example :
finalgrade = "High Pass"
the computations are done from right to left